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(android): return exception message (where it exists) #687

Merged
merged 4 commits into from
Aug 11, 2021

Conversation

dpa99c
Copy link
Contributor

@dpa99c dpa99c commented Nov 9, 2020

Platforms affected

Android

Motivation and Context

I use this plugin in multiple apps and sometimes users encounter errors when using the camera and ask for support.
To help with user support it would be useful to know the cause of the error by returning the exception message (where it exists) in the error message sent to the plugin error callback.
For example, this can be logged to analytics and used to help diagnose the cause of the error.

Description

Where an exception is raised and the plugin invokes the error callback, append the exception message to the returned error message.

Testing

Tested on Android device by forcing an exception by appending "FOO" to the imageUri, i.e. change line 615 to:

InputStream fileStream = org.apache.cordova.camera.FileHelper.getInputStreamFromUriString(imageUri.toString()+"FOO", cordova);

Resulting error callback message: Error capturing image: open failed: ENOENT (No such file or directory)

Checklist

  • I've run the tests to see all new and existing tests pass
  • [n/a] I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • [n/a] If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • [n/a] I've updated the documentation if necessary

Copy link
Member

@erisu erisu left a comment

Choose a reason for hiding this comment

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

LGTM 👍

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.

In other parts of the plugin we are using getLocalizedMessage instead of getMessage, so for consistency I think we should also use getLocalizedMessage here.
I get the exact message since it's not localized.

callbackContext.error(e.getLocalizedMessage());

src/android/CameraLauncher.java Outdated Show resolved Hide resolved
src/android/CameraLauncher.java Outdated Show resolved Hide resolved
src/android/CameraLauncher.java Outdated Show resolved Hide resolved
erisu and others added 3 commits August 11, 2021 16:51
Co-authored-by: jcesarmobile <jcesarmobile@gmail.com>
Co-authored-by: jcesarmobile <jcesarmobile@gmail.com>
Co-authored-by: jcesarmobile <jcesarmobile@gmail.com>
@erisu erisu merged commit e9db20e into apache:master Aug 11, 2021
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.

None yet

3 participants