Remove Kotlin error name and stacktrace from js error.message
Feature Request/Enhancement
Hello again! I find that if I throw a Error in Kotlin and catch it in js, the js error.message has the name and stacktrace of that kotlin error, which is not same as Swift.
It would be better to remove these useless info to keep error.message clean.
override fun doSomething(): Promise<String?> {
return Promise.rejected(Error("Failed"))
}
and in js log its message
try {
await doSomething();
} catch (error) {
console.log(error.message);
}
and the log looks like
java.lang.Error: Failed
at com.margelo.nitro.deviceinfo.DeviceInfo.doSomething(DeviceInfo.kt:120)
at com.facebook.jni.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.kt:21)
at android.os.Looper.loopOnce(Looper.java:222)
at android.os.Looper.loop(Looper.java:314)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$Companion.startNewBackgroundThread$lambda$1(MessageQueueThreadImpl.kt:175)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$Companion.$r8$lambda$ldnZnqelhYFctGaUKkOKYj5rxo4(Unknown Source:0)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$Companion$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
at java.lang.Thread.run(Thread.java:1012)
Are there any existing workarounds?
No response
Additional information
- [x] I checked the documentation and couldn't find this feature.
- [ ] I can create a PR to implement this feature. (See Contributing for more information)
- [x] I searched for similar issues in this repository and found none.
remove these useless info
I think the type of error and stacktrace is very important for library devs, so this should absolutely be part of the JS Error.
But I agree that it should not be within message, instead it should be;
error.message:Failederror.stacktrace:at com.margelo.nitro.deviceinfo.DeviceInfo.doSomething(DeviceInfo.kt:120)......error.type:java.lang.Error
Theoretically we can also add stacktrace and type in Swift:
Thread.callStackSymbols:0 MyApp 0x0000000100000abc functionC() + 44 1 MyApp 0x0000000100000a50 functionB() + 32 2 MyApp 0x00000001000009f0 functionA() + 16 3 MyApp 0x0000000100000990 main + 50 ...type(of: error):RuntimeError
Error.prototype.name could be our type property 🤷
Maybe we can also add a code key to the Kotlin/Swift/TS... Error ? This is useful when I previously use the old arch.
Error is a type defined by JS, so I can't add anything there.