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

IOS setup_log_stream Panic Exception #2296

Open
TibiToz opened this issue Sep 12, 2024 · 5 comments
Open

IOS setup_log_stream Panic Exception #2296

TibiToz opened this issue Sep 12, 2024 · 5 comments
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc

Comments

@TibiToz
Copy link

TibiToz commented Sep 12, 2024

Hi,

I set up the logger to be able to send logs to Dart. I used the basic example for it. It is working great on Android, but on IOS an exception occurs when the log_stream is instantiated ( or re-instantiated but I don't understand how it could be called 2 times if it is the case).

Physical device:
IOS 15.8.3
iPad Air 2 (Model A1566)

Here are the error logs and my logger init code.
Rust:

flutter_logger::flutter_logger_init!(LevelFilter::Info);

#[flutter_rust_bridge::frb(init)]
pub fn init_app() {
    flutter_rust_bridge::setup_default_user_utils();
}

Dart:

Future setupLogger() async {
  setupLogStream().listen((msg) {
      logger("${msg.logLevel} ${msg.lbl.padRight(8)}: ${msg.msg}");
  });
}


Future<void> main() async {
  await RustLib.init();
  await setupLogger();
}

Error:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PanicException(called Result::unwrap() on an Err value: SetLoggerError(())Backtrace [{ fn: "std::backtrace::Backtrace::create" }, { fn: "flutter_rust_bridge::misc::panic_backtrace::PanicBacktrace::setup::{{closure}}" }, { fn: "std::panicking::rust_panic_with_hook" }, { fn: "std::panicking::begin_panic_handler::{{closure}}" }, { fn: "std::sys_common::backtrace::rust_end_short_backtrace" }, { fn: "_rust_begin_unwind" }, { fn: "core::panicking::panic_fmt" }, { fn: "core::result::unwrap_failed" }, { fn: "rust_lib_app::api::discovery::setup_log_stream" }, { fn: "rust_lib_app::frb_generated::wirecrate__api__discovery__setup_log_stream_impl::{{closure}}::{{closure}}::{{closure}}" }, { fn: "rust_lib_app::frb_generated::wire__crate__api__discovery__setup_log_stream_impl::{{closure}}::{{closure}}" }, { fn: "<flutter_rust_bridge::handler::implementation::executor::SimpleExecutor<EL,TP,AR> as flutter_rust_bridge::handler::executor::Executor>::execute_normal::{{closure}}::{{closure}}" }, { fn: "<core::panic::unwind_safe::AssertUnwindSafe as core::ops::function::FnOnce<()>>::call_once" }, { fn: "std::panicking::try::do_call" }, { fn: "rust_try" }, { fn: "std::panicking::try" }, { fn: "std::panic::catch_unwind" }, { fn: "flutter_rust_bridge::misc::panic_backtrace::PanicBacktrace::catch_unwind" }, { fn: "<flutter_rust_bridge::handler::implementation::executor::SimpleExecutor<EL,TP,AR> as flutter_rust_bridge::handler::executor::Executor>::execute_normal::{{closure}}" }, { fn: "::call_box" }, { fn: "threadpool::spawn_in_pool::{{closure}}" }, { fn: "std::sys_common::backtrace::rust_begin_short_backtrace" }, { fn: "std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}}" }, { fn: "<core::panic::unwind_safe::AssertUnwindSafe as core::ops::function::FnOnce<()>>::call_once" }, { fn: "std::panicking::try::do_call" }, { fn: "__rust_try" }, { fn: "std::panicking::try" }, { fn: "std::thread::Builder::spawn_unchecked::{{closure}}" }, { fn: "core::ops::function::FnOnce::call_once{{vtable.shim}}" }, { fn: "std::sys::pal::unix::thread::Thread::new::thread_start" }])

#0 SimpleDecoder.decode (package:flutter_rust_bridge/src/codec/base.dart:35:9)

#1 SseCodec._decode (package:flutter_rust_bridge/src/codec/sse.dart:42:55)

#2 SseCodec.decodeObject (package:flutter_rust_bridge/src/codec/sse.dart:32:12)

#3 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:847:45)

#4 Future._propagateToListeners (dart:async/future_impl.dart:876:13)

#5 Future._completeWithValue (dart:async/future_impl.dart:652:5)

#6 Future._asyncCompleteWithValue. (dart:async/future_impl.dart:722:7)

#7 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)

#8 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)

Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel [user-branch], 3.22.0-3.0.pre, on macOS 14.6.1 23G93 darwin-arm64, locale en-CH)
    ! Flutter version 3.22.0-3.0.pre on channel [user-branch] at /Users/rd/Documents/Flutter/flutter
      Currently on an unknown channel. Run flutter channel to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at
      https://flutter.dev/docs/get-started/install.
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.78.2)
[✓] Connected device (3 available)
    ! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or
      associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
[✓] Network resources
@fzyzcjy
Copy link
Owner

fzyzcjy commented Sep 12, 2024

setup_default_user_utils sets up the logger (see its source code for details), so if you setup your own logger, you will setup Rust system logger twice, and I guess that's the error

@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Sep 12, 2024
@TibiToz
Copy link
Author

TibiToz commented Sep 13, 2024

Yes that was the error, thank you.

If I'm using this logger init
flutter_logger::flutter_logger_init!(LevelFilter::Info);
Will the rust exceptions be logged ? Or should I manually log them ?

@fzyzcjy
Copy link
Owner

fzyzcjy commented Sep 13, 2024

flutter_logger is not developed by me, thus I guess you can ask the author of the package - cc @MnlPhlp :)

@MnlPhlp
Copy link
Contributor

MnlPhlp commented Sep 13, 2024

If setting up the logger twice is the problem why would it be different on ios and android?
Disabling the log feature of flutter_rust_bridge should solve it I think.

@TibiToz
Copy link
Author

TibiToz commented Sep 17, 2024

If setting up the logger twice is the problem why would it be different on ios and android? Disabling the log feature of flutter_rust_bridge should solve it I think.

Yup, disabling IOS log feature in frb resolved the issue. Thanks for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc
Projects
None yet
Development

No branches or pull requests

3 participants