fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
3.61k stars 254 forks source link

Exception in RustLib.init in Chrome #1912

Open aran opened 2 weeks ago

aran commented 2 weeks ago

Describe the bug

By default in a brand new project there is an exception thrown in RustLib.init in Chrome. It is swallowed and silent but the debugger sees it. Stack trace below. Flagging in case it leads to solving some other issues.

info: syncing channel updates for 'nightly-aarch64-apple-darwin'

  nightly-aarch64-apple-darwin unchanged - rustc 1.80.0-nightly (c987ad527 2024-05-01)

Steps to reproduce

  1. flutter_rust_bridge_codegen create repro
  2. flutter_rust_bridge_codegen generate && flutter_rust_bridge_codegen build-web
  3. Enable breakpoint on All Exceptions in VSCode
  4. Launch with ["--web-header", "Access-Control-Allow-Origin=*", "--web-header", "Cross-Origin-Embedder-Policy=require-corp", "--web-header", "Cross-Origin-Opener-Policy=same-origin"]

Logs

Exception has occurred.
Error
pkg/rust_lib_repro.js 673:21                                                  eval
pkg/rust_lib_repro.js 673:21                                                  eval
pkg/rust_lib_repro.js 673:21                                                  <fn>
pkg/rust_lib_repro.js 326:18                                                  handleError
pkg/rust_lib_repro.js 672:67                                                  __wbg_eval_020a6ea487e91ede
pkg/rust_lib_repro.js 287:10                                                  frb_pde_ffi_dispatcher_primary
packages/flutter_rust_bridge/src/generalized_frb_rust_binding/_web.dart 26:5  pdeFfiDispatcherPrimary
packages/flutter_rust_bridge/src/codec/pde.dart 15:30                         pdeCallFfi
packages/repro/src/rust/frb_generated.dart 112:9                              <fn>
packages/flutter_rust_bridge/src/main_components/handler.dart 16:17           executeNormal
packages/repro/src/rust/frb_generated.dart 109:20                             initApp
packages/repro/src/rust/frb_generated.dart 48:15                              executeRustInitializers
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54            runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5            _async
packages/repro/src/rust/frb_generated.dart 47:39                              executeRustInitializers
packages/flutter_rust_bridge/src/main_components/entrypoint.dart 63:11        initImpl
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50            <fn>
dart-sdk/lib/async/zone.dart 1661:54                                          runUnary
dart-sdk/lib/async/future_impl.dart 162:18                                    handleValue
dart-sdk/lib/async/future_impl.dart 838:44                                    handleValueCallback
dart-sdk/lib/async/future_impl.dart 867:13                                    _propagateToListeners
dart-sdk/lib/async/future_impl.dart 643:5                                     [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 713:7                                     callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                              _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                               _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7            <fn>

Expected behavior

No response

Generated binding code

No response

OS

macos

Version of flutter_rust_bridge_codegen

dev.32

Flutter info

`[✓] Flutter (Channel stable, 3.19.6, on macOS 14.4.1 23E224 darwin-arm64, locale en-US)`

Version of clang++

Apple clang version 15.0.0 (clang-1500.3.9.4) Target: arm64-apple-darwin23.4.0

Additional context

No response

fzyzcjy commented 2 weeks ago

Thanks for the report! It would be great to show a bit more. For example, the whole repo with all the code, including pkg/rust_lib_repro.js 673:21 and packages/flutter_rust_bridge/src/generalized_frb_rust_binding/_web.dart 26:5.

(If you recompile and the line numbers changed, remember to update them here ;) )

aran commented 2 weeks ago

https://github.com/aran/frb-exc-repro

fzyzcjy commented 2 weeks ago

Hmm I do not see the pkg/rust_lib_repro.js, maybe (for this repro only, surely) temporarily make it non-git-ignored to have a look.

image

aran commented 2 weeks ago

Sorry. Updated. https://github.com/aran/frb-exc-repro/blob/main/web/pkg/rust_lib_repro.js

fzyzcjy commented 2 weeks ago

Hmm, then it does not reveal a lot. Another way to debug is that, we can modify frb_generated.rs (e.g. pde_ffi_dispatcher_primary in this case), and add some logging to see what is happening. For example, I personally may add fn pde_ffi_dispatcher_primary() { log::info!("hi START"); ... log::info("hi stage 1"); ... } and if e.g. hi stage 1 is never printed, I know problem lies between START and hi-stage-1.