-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 + '"') |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
@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. |
I received following error
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/]"