Skip to content
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

[Wasm] JS exception not caught in async function #55466

Closed
sma opened this issue Apr 13, 2024 · 4 comments
Closed

[Wasm] JS exception not caught in async function #55466

sma opened this issue Apr 13, 2024 · 4 comments
Labels
area-dart2wasm Issues for the dart2wasm compiler. area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-js-interop Issues that impact all js interop

Comments

@sma
Copy link

sma commented Apr 13, 2024

I think, this issue is caused by a Dart wasm compiler bug.

This source code (a trivial Futter app) should work, but crashes because the exception on the JavaScript side isn't caught in initialize. Note that it works if initialize isn't an async function. Hence, my guess that the wasm compiler has a problem here.

import 'dart:js_interop';

import 'package:flutter/material.dart';

void main() async {
  await initialize();
  runApp(const MaterialApp(home: Scaffold(body: Text('It works!'))));
}

Future<void> initialize() async {
  try {
    doSomething();
  } catch (e) {
    // ignored
  }
  print('not reached');
}

@JS()
external void doSomething();

For the JavaScript side, I added this to index.html:

    function doSomething() {
      throw new Error('This is a JavaScript error.');
    }

To compile the Flutter app, I use:

flutter build web -t lib/bug.dart --wasm --no-strip-wasm

To run it, I use the httpd command from the documentation. See that other bug report.

My configuration:

$ flutter --version
Flutter 3.22.0-10.0.pre.13 • channel master • https://github.com/flutter/flutter.git
Framework • revision 46fbb73440 (11 hours ago) • 2024-04-12 18:41:57 -0400
Engine • revision 1a13c7d1f4
Tools • Dart 3.5.0 (build 3.5.0-47.0.dev) • DevTools 2.34.1

Some additional details:

Here's the original exception in Chrome dev tools with "break on exceptions":
image

Here's the WASM exception handler, I guess:
image

and here's the stack trace:

JavaScriptError
main.dart.mjs:56     at initialize inner (http://localhost:8080/main.dart.wasm:wasm-function[7714]:0x12ea5b)
    at main inner.1 (http://localhost:8080/main.dart.wasm:wasm-function[1817]:0xa96f7)
    at main.1 (http://localhost:8080/main.dart.wasm:wasm-function[1150]:0x99520)
    at bootstrapEngine closure at org-dartlang-sdk:///lib/ui_web/ui_web/initialization.dart:35:16 inner (http://localhost:8080/main.dart.wasm:wasm-function[7725]:0x12ef51)
    at _awaitHelperWithTypeCheck closure at org-dartlang-sdk:///dart-sdk/lib/_internal/wasm/lib/async_patch.dart:97:16 (http://localhost:8080/main.dart.wasm:wasm-function[1721]:0xa7c34)
    at closure wrapper at org-dartlang-sdk:///dart-sdk/lib/_internal/wasm/lib/async_patch.dart:97:16 trampoline (http://localhost:8080/main.dart.wasm:wasm-function[1726]:0xa7c9b)
    at _RootZone.runUnary (http://localhost:8080/main.dart.wasm:wasm-function[985]:0x94c79)
    at _Future._propagateToListeners (http://localhost:8080/main.dart.wasm:wasm-function[964]:0x947c5)
@parlough parlough added web-js-interop Issues that impact all js interop area-dart2wasm Issues for the dart2wasm compiler. area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. labels Apr 13, 2024
@kevmoo
Copy link
Member

kevmoo commented Apr 13, 2024

CC @eyebrowsoffire – someone else here?

@kevmoo
Copy link
Member

kevmoo commented Apr 13, 2024

Related? #55457

@eyebrowsoffire
Copy link
Contributor

Yep, it's a duplicate.

@eyebrowsoffire
Copy link
Contributor

Closing as a duplicate. Btw, good investigation @sma! We're working on a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart2wasm Issues for the dart2wasm compiler. area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-js-interop Issues that impact all js interop
Projects
None yet
Development

No branches or pull requests

4 participants