Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Conversation

@hffmnn
Copy link
Contributor

@hffmnn hffmnn commented Jul 5, 2019

Description

This PR adds support to send non-FlutterErrorDetails errors to Crashlytics that have not been caught by the Flutter.onError handler.

When e.g. a exception is thrown in a Future, then the error handler does not work and the crash will never be reported. By using runZoned and using its onError handler it is possible to catch those, but the current plugin only supports sending FlutterErrorDetails errors. I updated the example to make this point more clear.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@hffmnn hffmnn force-pushed the feature/runtime-exceptions branch from cd78021 to c6a5aa0 Compare July 5, 2019 12:00
final dynamic result = await channel
.invokeMethod<dynamic>('Crashlytics#onError', <String, dynamic>{
'exception': "${exception.toString()}",
'context': 'onRuntimeException',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what to send here, because we do not have ErrorDescription.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to just leave it out if there's nothing to say

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I double checked: The native method signatures the context gets send to are:
- (void)recordCustomExceptionName:(NSString *)name reason:(nullable NSString *)reason frameArray:(CLS_GENERIC_NSARRAY(CLSStackFrame *) *)frameArray; on iOS. In the end the context gets set on the reason parameter, which is nullable, so ✅.

On Android it looks like it does no get used at all, so ✅.

Will remove then.

}
}

Future<void> onRuntimeException(dynamic exception, dynamic stack) async {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming is hard. I guess there are better names for this method?

Copy link
Contributor

@collinjackson collinjackson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! We should land #1799 before this one. (Edit: Done!)

I think I'd like to rename onError to recordError to match other platforms, which will be a breaking change. This is a good opportunity to revisit the method signature as well.

It sounds like we need to support either a FlutterErrorDetails or an arbitrary error and stack, I'm debating whether to try to shoehorn them onto one method, or split it into two methods (recordFlutterError and recordError).

There's a bit of code duplication here, I think we should try to get more code re-use

final dynamic result = await channel
.invokeMethod<dynamic>('Crashlytics#onError', <String, dynamic>{
'exception': "${exception.toString()}",
'context': 'onRuntimeException',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to just leave it out if there's nothing to say

@hffmnn
Copy link
Contributor Author

hffmnn commented Jul 8, 2019

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes and removed cla: no labels Jul 8, 2019
@hffmnn hffmnn force-pushed the feature/runtime-exceptions branch from 41ec823 to a778d89 Compare July 8, 2019 20:01
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: no and removed cla: yes labels Jul 9, 2019
@hffmnn hffmnn force-pushed the feature/runtime-exceptions branch from bb496fb to 4180e59 Compare July 9, 2019 10:01
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes and removed cla: no labels Jul 9, 2019
@hffmnn
Copy link
Contributor Author

hffmnn commented Jul 9, 2019

There's a bit of code duplication here, I think we should try to get more code re-use

Sure. Let me know if you would like to keep the 2 methods or funnel all through one.

I think I'd like to rename onError to recordError to match other platforms, which will be a breaking change. This is a good opportunity to revisit the method signature as well.

I would start working on that, as soon as the API (one method vs two methods) decision is done.

@collinjackson
Copy link
Contributor

collinjackson commented Jul 22, 2019

We've made a (tentative) decision to go with two methods:

Future<void> recordFlutterError(FlutterErrorDetails details);
Future<void> recordError(dynamic error, StackTrace stackTrace, { dynamic context });

Example of usage:

void main() {
 FlutterError.onError = Crashlytics.instance.recordFlutterError;
 runZoned<Future<void>>(() async {
   runApp(MyApp());
 }, onError: Crashlytics.instance.recordError);
}

Let me know if you have any feedback, and if it looks good, I'd appreciate your help updating the PR. This is a breaking change, and we'll be making some other breaking changes at the same time, but I can handle that part.

@hffmnn hffmnn force-pushed the feature/runtime-exceptions branch from 4180e59 to 845d000 Compare July 24, 2019 14:54
@hffmnn
Copy link
Contributor Author

hffmnn commented Jul 24, 2019

@collinjackson I updated the PR with the new API and refactored the duplicated code. Let me know what you think.

Before I started I rebased to the latest master so I have no idea why some checks are failing with Execution failed for task ':app:buildPluginDebugFirebaseAuth'..

'keys': _prepareKeys(),
});
}
/// Submits non-fatal crash report to Firebase Crashlytics.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might work on this doc comment.

@collinjackson
Copy link
Contributor

@collinjackson I updated the PR with the new API and refactored the duplicated code. Let me know what you think.

Before I started I rebased to the latest master so I have no idea why some checks are failing with Execution failed for task ':app:buildPluginDebugFirebaseAuth'..

Don't worry about these failures, they're affecting master as well https://cirrus-ci.com/task/4801326419017728

Crashlytics.instance.enableInDevMode = true;

// Pass all uncaught errors to Crashlytics.
FlutterError.onError = (FlutterErrorDetails details) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be simpler here to just say FlutterError.onError = Crashlytics.instance.recordFlutterError;


runZoned<Future<void>>(() async {
runApp(MyApp());
}, onError: (dynamic error, dynamic stack) async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be simpler here to just say onError: Crashlytics.instance.recordError

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

Co-Authored-By: Collin Jackson <[email protected]>
@hffmnn hffmnn force-pushed the feature/runtime-exceptions branch from 8118c88 to 20480ba Compare July 25, 2019 08:45
@collinjackson
Copy link
Contributor

Looks good. Thanks for the contribution.

@collinjackson collinjackson merged commit 589f4e1 into flutter:master Jul 25, 2019
mithun-mondal pushed a commit to bKash-developer/archived_plugins that referenced this pull request Aug 6, 2019
* update AUTHORS file

* add new method recordError

* rename onError to recordFlutterError

Co-Authored-By: Collin Jackson <[email protected]>
julianscheel pushed a commit to jusst-engineering/plugins that referenced this pull request Mar 11, 2020
* update AUTHORS file

* add new method recordError

* rename onError to recordFlutterError

Co-Authored-By: Collin Jackson <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants