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

Unhandled exception when reading file on Android #6

Closed
amake opened this issue Jun 8, 2020 · 3 comments
Closed

Unhandled exception when reading file on Android #6

amake opened this issue Jun 8, 2020 · 3 comments

Comments

@amake
Copy link
Contributor

amake commented Jun 8, 2020

I had a crash report in Google Play Console caused by file_picker_writable trying to read a non-existent file (see amake/orgro#10).

The trace was

java.io.FileNotFoundException:
  at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel (DatabaseUtils.java:149)
  at android.content.ContentProviderProxy.openTypedAssetFile (ContentProviderProxy.java:705)
  at android.content.ContentResolver.openTypedAssetFileDescriptor (ContentResolver.java:1694)
  at android.content.ContentResolver.openAssetFileDescriptor (ContentResolver.java:1510)
  at android.content.ContentResolver.openInputStream (ContentResolver.java:1194)
  at codeux.design.filepicker.file_picker_writable.FilePickerWritableImpl$copyContentUriAndReturnFileInfo$2.invokeSuspend (FilePickerWritableImpl.java:154)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (BaseContinuationImpl.java:8)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.java:93)
  at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely (CoroutineScheduler.java)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask (CoroutineScheduler.java:14)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker (CoroutineScheduler.java:28)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run (CoroutineScheduler.java)

Unfortunately the coroutines ruin the trace, so I can't see how exactly execution got to FilePickerWritableImpl#copyContentUriAndReturnFileInfo. But there is some code path that doesn't properly catch exceptions.

I think one problem might be that you use launch to start coroutines in several places, but have the try/catch outside of launch. Uncaught exceptions in launched coroutines aren't forwarded to the parent scope and will crash the app on Android (link).

@amake amake changed the title Handle exception when reading file on Android Unhandled exception when reading file on Android Jun 8, 2020
@hpoul
Copy link
Owner

hpoul commented Jun 8, 2020

You are right about launch.. no idea why i missed that.. although there are still two launch calls in FilePickerWritablePlugin they don't look very dangerous..
thanks for your PR #7 .. i improved a bit upon it, by simply moving the launch one level up so there is still just one try/catch.. i think this should accomplish about the same: https://github.com/hpoul/file_picker_writable/pull/8/files - any thoughts?

@amake
Copy link
Contributor Author

amake commented Jun 8, 2020

Looks good to me. I'll close my PR then.

@amake
Copy link
Contributor Author

amake commented Jun 9, 2020

This was addressed by #8

@amake amake closed this as completed Jun 9, 2020
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

No branches or pull requests

2 participants