Martin
Martin

Reputation: 121

FirebaseCrashlytics, will not report Exceptions but running .crash will

Below is a code that i have to initialize an run my app with. As a test i have a future that will throw an exception (out of range), this is how ever not sent to crashlystics?

If i issue a FirebaseCrashlystics.instance.crash() it will send a report. I have changed the filter to Event-type="non-fatals" but i can not see my errors there.

I don't know what i am missing?

class AppConfig {
  final String appTitle;
  final BuildFlavor buildFlavor;
  final bool initializeCrashlytics, enableCrashlyticsInDevmode;

  AppConfig(
      {@required this.appTitle,
      @required this.buildFlavor,
      this.initializeCrashlytics = true,
      this.enableCrashlyticsInDevmode = true});

  Future<void> _testAsyncErrorOnInit() async {
    Future<void>.delayed(
      const Duration(seconds: 2),
      () {
        final List<int> list = <int>[];
        print(list[100]);
      },
    );
  }

  Future startCrashlytics() async {
    Function originalError = FlutterError.onError;
    if (this.initializeCrashlytics) {
      await FirebaseCrashlytics.instance
          .setCrashlyticsCollectionEnabled(this.enableCrashlyticsInDevmode);
      FlutterError.onError = (FlutterErrorDetails errorDetails) async {
        await FirebaseCrashlytics.instance.recordFlutterError(errorDetails);
        originalError(errorDetails);
      };
      FirebaseCrashlytics.instance.crash(); << This works

      // await _testAsyncErrorOnInit(); << This doesn't Yes i do comment crash and uncomment this.
    }
  }

  Future run() async {
    // Lägg in initiering av firebase, crashlytics
    WidgetsFlutterBinding.ensureInitialized();
    await Firebase.initializeApp();

    await startCrashlytics();

    runApp(ElectronicCupongs(appTitle: appTitle));
  }
}

Upvotes: 1

Views: 814

Answers (1)

Underscore
Underscore

Reputation: 1062

I see you checked the package's example, but is your app wrapped in runZonedGuarded?

The example page contains the required details, but you can also check the package's files or, a more readable format, FlutterFire.

Upvotes: 1

Related Questions