Open srujzs opened 6 months ago
Please include code snippets on how to test it, for example:
testWidgets('JavaScript function will throws error',
(WidgetTester tester) async {
expect(
() async {
await javaScriptFunction();
},
throwsA(...),
);
});
Ack. I suspect the best we can do today is either expect an Error
or a JSObject
(which I think is the case when it's just a JS Error
in DDC).
Related bug: https://github.com/dart-lang/sdk/issues/55481
Currently, dart2wasm catches all JS exceptions as a singular error type:
https://github.com/dart-lang/sdk/blob/ad95bb6f89eb3aa36b129320fba47c29574b7084/sdk/lib/_internal/wasm/lib/errors_patch.dart#L40
This is a private type, so we don't have a good way to determine if this was a JS error (besides
toString
).DDC and dart2js use interceptors to differentiate between JS errors and to allow users to use a JS interop interface to interact with the error.
Due to these inconsistencies, some ways of catching JS errors will work in ddc and dart2js, but fail in dart2wasm. We should add documentation to dart.dev on how we expect users to catch JS errors and inspect the error (if even possible).
It seems like the only consistent way to do this today is to just catch it as an arbitrary error:
cc @MaryaBelanger