nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Remove Kotlin error name and stacktrace from js error.message

Open Phecda opened this issue 2 months ago • 5 comments

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

Phecda avatar Oct 31 '25 09:10 Phecda

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: Failed
  • error.stacktrace: at com.margelo.nitro.deviceinfo.DeviceInfo.doSomething(DeviceInfo.kt:120)......
  • error.type: java.lang.Error

mrousavy avatar Oct 31 '25 15:10 mrousavy

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

mrousavy avatar Oct 31 '25 16:10 mrousavy

Error.prototype.name could be our type property 🤷

mrousavy avatar Oct 31 '25 16:10 mrousavy

Maybe we can also add a code key to the Kotlin/Swift/TS... Error ? This is useful when I previously use the old arch.

Phecda avatar Oct 31 '25 16:10 Phecda

Error is a type defined by JS, so I can't add anything there.

mrousavy avatar Nov 01 '25 14:11 mrousavy