felangel/bloc

refactor: stop losing the original stack trace from dart 2.16

クローズ

#2,995 opened on 2021/11/21

 (5 件のコメント) (1 件のリアクション) (1 人の担当者)Dart (3,419 件のフォーク)batch import
examplegood first issuerefactor

Repository metrics

Stars
 (12,452 個のスター)
PR merge metrics
 (平均マージ 2d 22h) (30d で 5 merged PRs)

説明

You must stop losing the original source stack trace like this (just for example):

https://github.com/felangel/bloc/blob/a3a9b2dba6546480d4ea26931ed024f274b9a7a9/examples/flutter_firebase_login/packages/authentication_repository/lib/src/authentication_repository.dart#L206-L210

it's big trouble, to read exceptions without source stacktraces, especially in crashlytics or sentry like logs

from dart 2.16 you must use Error.throwWithStackTrace like this:

//@dart=2.16

...

} on FirebaseAuthException catch (e, stackTrace) {
  Error.throwWithStackTrace(
    SignUpWithEmailAndPasswordFailure.fromCode(e.code),
    stackTrace,
  );
}

also, instead:

} catch (_) {

you must write:

} on Object {

or:

} on Object catch (error, stackTrace) {

コントリビューターガイド