Imagine someone is writing a WebSocket client. MDN has a couple examples for handling WebSocket errors, e.g. in https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onerror and https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/error_event. Both just call console.log or console.error with the argument.
Consider this example:
const socket = new WebSocket('ws://localhost:8080');
socket.onerror = function(event) {
console.error("WebSocket error observed:", event);
};
Running it as deno run test.js produces the following output:
WebSocket error observed: ErrorEvent { isTrusted: false }
Not very informative. https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent does list the error property, but it's not easily discoverable (there are no links to it from any WebSocket documentation pages as far as I can tell) and its significance isn't obvious.
There are a couple issues here... first in some cases WebSocket isn't actually raising an EventError, but just a plain Event:
and
and
In addition, while our Event implementation is spec compliant, most browsers implement some sort of custom inspect to output non-owned properties on the event. For you get the following in Chrome:
> new ErrorEvent("error", { error: new TypeError("hello"), message: "hello" })
ErrorEvent聽{isTrusted: false, message: "hello", filename: "", lineno: 0, colno: 0,聽鈥
Hi. Could I please have a go at this one?
@ross-weir Sure! All help is appreciated :-)
This appears to be affecting all events:
Deno:
> new Event("testing")
Event { isTrusted: false }
Chrome:
> new Event("testing)
Event聽{isTrusted: false, type: "testing", target: null, currentTarget: null, eventPhase: 0,聽鈥
I'm not knowledgeable enough to come up with a solution/pinpoint the problem but I've found that it might have something to do with the properties being defined on the prototype - isTrusted is the only property defined on the instance.
I would be happy to continue working on this with some guidance :-)