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

[firebase_crashlytics] Handle case where function isn't in class for stack #1831

Merged
merged 6 commits into from
Jul 11, 2019

Conversation

rmtmckenzie
Copy link
Contributor

Description

Currently, the stacktrace parser can't handle it when there is a method without a class in dart - it instead throws its own exception and loses the original one!

This PR handles the case where there is no class name.

There is a slight caveat to the fix on Android - firebase reporting uses a StackTraceElement which requires a class (which makes sense in Java since you can't have Class-less methods), so on Android class-less methods are reported as .<functionName> whereas on iOS they are simply reported as <className>.

I don't think this is a big problem as there seem to be other differences between how the stacktraces are reported on Android and iOS anyways.

i.e. iOS:
image

Android:
image

Related Issues

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.

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.

Looks great! Thanks for adding a test. One suggestion, which I'll commit for you.

@@ -103,7 +103,8 @@ private StackTraceElement generateStackTraceElement(Map<String, String> errorEle
String className = errorElement.get("class");
String methodName = errorElement.get("method");

return new StackTraceElement(className == null ? "" : className, methodName, fileName, Integer.parseInt(lineNumber));
return new StackTraceElement(
className == null ? "" : className, methodName, fileName, Integer.parseInt(lineNumber));
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 className ?? "" would be more readable

Suggested change
className == null ? "" : className, methodName, fileName, Integer.parseInt(lineNumber));
className ?? "", methodName, fileName, Integer.parseInt(lineNumber));

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, never mind, this is Java not Dart :)

Copy link
Contributor Author

@rmtmckenzie rmtmckenzie Jul 10, 2019

Choose a reason for hiding this comment

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

Unless you know something I don't, I don't think that Java has a null coalescing operator yet... (oops, for some reason github didn't show me your second comment until after I wrote this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I agree that's definitely more readable 😄

@collinjackson collinjackson merged commit f8efbe8 into flutter:master Jul 11, 2019
mithun-mondal pushed a commit to bKash-developer/plugins that referenced this pull request Aug 6, 2019
…stack (flutter#1831)

* Handle case where no class in dart and android (ios is fine)
julianscheel pushed a commit to jusst-engineering/plugins that referenced this pull request Mar 11, 2020
…stack (flutter#1831)

* Handle case where no class in dart and android (ios is fine)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants