fix: print stacktrace on error

This commit is contained in:
Marc Rousavy 2021-06-29 10:34:48 +02:00
parent fe745cc296
commit 359fd00c73

View File

@ -204,7 +204,8 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
GlobalScope.launch(Dispatchers.Main) { GlobalScope.launch(Dispatchers.Main) {
try { try {
configureSession() configureSession()
} catch (e: CameraError) { } catch (e: Throwable) {
Log.e(TAG, "Failed to configure session after setting frame processor! ${e.message}")
invokeOnError(e) invokeOnError(e)
} }
} }
@ -275,10 +276,7 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
} }
} catch (e: Throwable) { } catch (e: Throwable) {
Log.e(TAG, "update() threw: ${e.message}") Log.e(TAG, "update() threw: ${e.message}")
when(e) { invokeOnError(e)
is CameraError -> invokeOnError(e)
else -> invokeOnError(UnknownCameraError(e))
}
} }
} }
} }
@ -459,11 +457,18 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, "cameraInitialized", null) reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, "cameraInitialized", null)
} }
private fun invokeOnError(error: CameraError) { private fun invokeOnError(error: Throwable) {
Log.e(TAG, "invokeOnError(...):")
error.printStackTrace()
val cameraError = when (error) {
is CameraError -> error
else -> UnknownCameraError(error)
}
val event = Arguments.createMap() val event = Arguments.createMap()
event.putString("code", error.code) event.putString("code", cameraError.code)
event.putString("message", error.message) event.putString("message", cameraError.message)
error.cause?.let { cause -> cameraError.cause?.let { cause ->
event.putMap("cause", errorToMap(cause)) event.putMap("cause", errorToMap(cause))
} }
val reactContext = context as ReactContext val reactContext = context as ReactContext