Skip to content

Fixing error output for non-error instance #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

martinheidegger
Copy link

I received following error

TypeError: Cannot read property 'stack' of undefined
at WebSocket.window.onerror (/Users/m/Documents/datproject/sdk/node_modules/electron-stream/lib/preload.js:23:23)
at /Users/m/Documents/datproject/sdk/node_modules/electron-stream/lib/preload.js:23:23

Noticing that an unhandled websocket error event is also handled by the onerror handler and causes above error.

This PR should fix that error and give more information if other, non-traditional, errors occur.

As far as events are concerned: The target can give insight on where the error occured, however in my case it resulted in an error message like Unhandled error event at WebSocket {} which didn't tell me much, so I added a .toString(){} method on the websocket giving me a bit more information which was meant. Now it shows an error message like: Unhandled error event at WebSocket {} "[object WebSocket, url=ws://localhost:9001/]"

Copy link
Owner

@juliangruber juliangruber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for the late review, looks mostly gtm

lib/preload.js Outdated
if (err) {
console.error((err.stack || err.message || err) + '\n at ' + file + ':' + line + ':' + column);
} else if (msg instanceof Event) {
console.error('Unhandled error event at', msg.target, '"' + msg.target + '"')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why msg.taget twice here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first time it is passed as object, the second time stringified, the reason for this is to easier identify an error once occurred. Depending on the environment the object visualization may help more or less than the toString() info.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain in which case stringifying the object helps?

This is in the browser:

const obj = { oh: 'hi' }
console.log(obj, String(obj))
// => {oh: "hi"} "[object Object]"

and this in node:

const obj = { oh: 'hi' }
console.log(obj, String(obj))
// => { oh: 'hi' } [object Object]

The console.error(obj) should be enough.

lib/preload.js Outdated
} else if (msg instanceof Event) {
console.error('Unhandled error event at', msg.target, '"' + msg.target + '"')
} else {
var out = msg;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know in which case this condition would happen?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh. no, i added it for "in case". Since it seems to be a possibility, from the argument pattern.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a comment for this, as it wasn't obvious to me?

@martinheidegger
Copy link
Author

@juliangruber Thank you for your review, I decided to rewrite this PR in 06e1ebb. I added comments and explanations to previous questions. Also now it will show clearly which "if" clause the error is in (Error, ErrorEvent, Event, other) and add the location as well as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants