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

Handle unhandled exceptions reading file on Android #7

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,51 +126,45 @@ class FilePickerWritableImpl(
)
return true
}
try {
return when (requestCode) {
REQUEST_CODE_OPEN_FILE -> {
val fileUri = data?.data
if (fileUri != null) {
plugin.logDebug("Got result $fileUri")
plugin.launch {
when (requestCode) {
REQUEST_CODE_OPEN_FILE -> {
val fileUri = data?.data
if (fileUri != null) {
plugin.logDebug("REQUEST_CODE_OPEN_FILE: Got result $fileUri")
plugin.launch {
try {
handleFileUriResponse(result, fileUri)
} catch (e: Exception) {
plugin.logDebug("Error during handling file packer result.", e)
result.error("FatalError", "Error handling file picker callback. $e", null)
}
} else {
plugin.logDebug("Got RESULT_OK with null fileUri?")
result.success(null)
}
true
} else {
plugin.logDebug("Got RESULT_OK with null fileUri?")
result.success(null)
}
REQUEST_CODE_CREATE_FILE -> {
val initialFileContent = filePickerCreateFile
?: throw FilePickerException("illegal state - filePickerCreateFile was nul")
val fileUri =
requireNotNull(data?.data) { "RESULT_OK with null file uri $data" }
plugin.logDebug("Got result $fileUri")
plugin.launch {
handleFileUriCreateResponse(
result,
fileUri,
initialFileContent
)
}
REQUEST_CODE_CREATE_FILE -> {
val initialFileContent = filePickerCreateFile
?: throw FilePickerException("illegal state - filePickerCreateFile was nul")
val fileUri =
requireNotNull(data?.data) { "RESULT_OK with null file uri $data" }
plugin.logDebug("REQUEST_CODE_CREATE_FILE: Got result $fileUri")
plugin.launch {
try {
handleFileUriCreateResponse(result, fileUri, initialFileContent)
} catch (e: Exception) {
plugin.logDebug("Error during handling file packer result.", e)
result.error("FatalError", "Error handling file picker callback. $e", null)
}

true
}
else -> {
// can never happen, we already checked the result code.
throw IllegalStateException("Unexpected requestCode $requestCode")
}
}
} catch (e: Exception) {
plugin.logDebug("Error during handling file packer result.", e)
result.error(
"FatalError",
"Error handling file picker callback. $e",
null
)
return true
else -> {
// can never happen, we already checked the result code.
throw IllegalStateException("Unexpected requestCode $requestCode")
}
}
return true
}

@MainThread
Expand Down Expand Up @@ -335,7 +329,11 @@ class FilePickerWritableImpl(
// }
plugin.launch {
if (isInitialized) {
handleUri(data)
try {
handleUri(data)
} catch (e: Exception) {
plugin.logDebug("Error trying to handle intent data $data: $e")
}
} else {
initOpenUrl = data
}
Expand Down