Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): return proper Error objects from native #1950

Merged
merged 2 commits into from
Sep 30, 2019
Merged

fix(core): return proper Error objects from native #1950

merged 2 commits into from
Sep 30, 2019

Conversation

diachedelic
Copy link
Contributor

@diachedelic diachedelic commented Sep 11, 2019

If I receive news of a Capacitor plugin error via sentry, there are no stack traces because fromNative (in native-bridge.js) throws a deserialized JSON object, not an Error. It's not even clear that the error is from a Capacitor plugin, as it's usually something like { message: "File not found" }.

image

image

This pull request transforms the error objects into actual Errors before they are thrown (well, passed to the callback/rejected). Now, at least one can see that the error originated from the native bridge:

image

Note that this PR uses Object.assign - I'm not sure whether Capacitor supports platforms without it. This is the MDN compatibility table:

image

@diachedelic
Copy link
Contributor Author

I figured Object.assign not being supported by Android WebView was probably a problem, so I replaced it with an old school solution.

@josh-m-sharpe
Copy link
Contributor

If this is true - big 👍

Copy link
Member

@jcesarmobile jcesarmobile left a comment

Choose a reason for hiding this comment

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

Thanks! it's really a bug, web and electron return proper errors, but Android and iOS weren't.

@jcesarmobile jcesarmobile changed the title ensure thrown errors contain stacktraces fix(core): return proper Error objects from native Sep 30, 2019
@jcesarmobile jcesarmobile merged commit 2fa29e3 into ionic-team:master Sep 30, 2019
@diachedelic diachedelic deleted the from-native-errors branch October 1, 2019 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants