diff --git a/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt b/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt index 53a92f3..f94bc65 100644 --- a/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt +++ b/android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt @@ -186,7 +186,10 @@ class ImageEditorModuleImpl(private val reactContext: ReactApplicationContext) { copyExif(reactContext, Uri.parse(uri), tempFile) } promise.resolve(getResultMap(tempFile, cropped, mimeType, includeBase64)) - } catch (e: Exception) { + } catch (e: Throwable) { + // Errors (e.g. OutOfMemoryError while decoding) must be turned into a rejection + // too: they don't extend Exception and would otherwise escape the coroutine and + // crash the app, leaving the promise unsettled. promise.reject(e) } } @@ -219,7 +222,10 @@ class ImageEditorModuleImpl(private val reactContext: ReactApplicationContext) { BitmapRegionDecoder.newInstance(it) } else { @Suppress("DEPRECATION") BitmapRegionDecoder.newInstance(it, false) - } ?: throw Error("Could not create bitmap decoder. Uri: $uri") + } + ?: throw JSApplicationIllegalArgumentException( + "Could not create bitmap decoder. Uri: $uri" + ) val imageHeight: Int = decoder.height val imageWidth: Int = decoder.width @@ -283,7 +289,10 @@ class ImageEditorModuleImpl(private val reactContext: ReactApplicationContext) { BitmapRegionDecoder.newInstance(it) } else { @Suppress("DEPRECATION") BitmapRegionDecoder.newInstance(it, false) - } ?: throw Error("Could not create bitmap decoder. Uri: $uri") + } + ?: throw JSApplicationIllegalArgumentException( + "Could not create bitmap decoder. Uri: $uri" + ) val orientation = getOrientation(reactContext, Uri.parse(uri)) val (x, y) =