bugsnag / bugsnag-flutter

BugSnag crash reporting for Flutter apps
https://docs.bugsnag.com/platforms/flutter/
MIT License
11 stars 11 forks source link

[Native-first Module] bugsnag.attach throws on a hot restart (minor problem) #173

Closed scottinet closed 1 year ago

scottinet commented 2 years ago

Describe the bug

This is, to me, more of a developer experience problem. As a bug, I consider it a minor one.

During development phases, when a hot-restarts is triggered, bugsnag.attach throws the following exception:

IllegalStateException
bugsnag.attach() may not be called more than once

com.bugsnag.flutter.BugsnagFlutter.attach(BugsnagFlutter.java:57), 
com.bugsnag.flutter.BugsnagFlutterPlugin$$ExternalSyntheticLambda1.invoke(Unknown Source:4), 
com.bugsnag.flutter.BugsnagFlutterPlugin.onMethodCall(BugsnagFlutterPlugin.java:66), 
io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262), 
io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295), 
io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319), io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12), 
android.os.Handler.handleCallback(Handler.java:938), android.os.Handler.dispatchMessage(Handler.java:99), 
android.os.Looper.loopOnce(Looper.java:201), android.os.Looper.loop(Looper.java:288), 
android.app.ActivityThread.main(ActivityThread.java:7842), java.lang.reflect.Method.invoke(Native Method), 
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548), 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

Steps to reproduce

  1. Create a native-first flutter module
  2. Start an emulator/simulator, make sure that your module is up & running
  3. In devtools, trigger a hot-restart (code source change, or manual trigger) => bugsnag throws the exception above

Environment

Workaround

Simple workaround, as we don't really need bugsnag during development stages: don't attach bugsnag during debug sessions.

if (kDebugMode) {
    runApp(MyApp());
  } else {
    bugsnag.attach(runApp: () => runApp(MyApp()));
  }
luke-belton commented 2 years ago

Hi @scottinet - thanks for raising this. Our team are going to investigate this and we'll keep you updated on this thread 👍

luke-belton commented 1 year ago

Hi @scottinet, we've just released https://github.com/bugsnag/bugsnag-flutter/releases/tag/v2.4.0 which includes a fix to not trigger errors with native-first hot reloads where bugsnag-attach is used 🎉 Thanks again for reporting this!