From a5dec1bebcaa41006e237576da8fac97cf65d2f7 Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Thu, 13 Apr 2023 10:54:09 +0200 Subject: [PATCH 1/9] Add throw stringified NSException from Obj-C and capture it in JSC --- .../ReactCommon/jsc/JSCRuntime.cpp | 5 +++++ .../ios/ReactCommon/RCTTurboModule.mm | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/react-native/ReactCommon/jsc/JSCRuntime.cpp b/packages/react-native/ReactCommon/jsc/JSCRuntime.cpp index 7958519e683f6d..fea1d0bc2d33c7 100644 --- a/packages/react-native/ReactCommon/jsc/JSCRuntime.cpp +++ b/packages/react-native/ReactCommon/jsc/JSCRuntime.cpp @@ -1240,6 +1240,11 @@ jsi::Function JSCRuntime::createFunctionFromHostFunction( exceptionString += ex.what(); *exception = makeError(rt, exceptionString); res = JSValueMakeUndefined(ctx); + } catch (const std::string &ex) { + std::string exceptionString("Exception in HostFunction: "); + exceptionString += ex; + *exception = makeError(rt, exceptionString); + res = JSValueMakeUndefined(ctx); } catch (...) { std::string exceptionString("Exception in HostFunction: "); *exception = makeError(rt, exceptionString); diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm index e56672ad0dd275..b2974b803bbe1f 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm @@ -211,6 +211,16 @@ static int32_t getUniqueId() return [callback copy]; } +static NSString *converNSExceptionToString(NSException *exception) +{ + NSMutableString *stack = [[NSMutableString alloc] init]; + for (NSString* symbol in exception.callStackSymbols) { + [stack appendFormat:@"%@\u2028", symbol]; + } + + return [NSString stringWithFormat:@"%@\u2028%@\u2028%@\u2028", exception.name, exception.reason, stack]; +} + namespace facebook { namespace react { @@ -378,8 +388,13 @@ static int32_t getUniqueId() } // TODO(T66699874) Should we guard this with a try/catch? - [inv invokeWithTarget:strongModule]; - [retainedObjectsForInvocation removeAllObjects]; + @try { + [inv invokeWithTarget:strongModule]; + } @catch (NSException *exception) { + throw std::string([converNSExceptionToString(exception) UTF8String]); + } @finally { + [retainedObjectsForInvocation removeAllObjects]; + } if (!wasMethodSync) { TurboModulePerfLogger::asyncMethodCallExecutionEnd(moduleName, methodNameStr.c_str(), asyncCallCounter); From 6a721fa1fa63f17e042c8fdc305606cd08cd0f4a Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Thu, 13 Apr 2023 14:55:53 +0200 Subject: [PATCH 2/9] Add java stringified stack trace to the JS error --- .../platform/android/ReactCommon/JavaTurboModule.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp index dc5a4d74efd35c..c7aab40c125793 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp @@ -468,7 +468,15 @@ jsi::Value JavaTurboModule::invokeJavaMethod( } else { TMPL::asyncMethodCallFail(moduleName, methodName); } - throw; + auto exception = std::current_exception(); + auto throwable = facebook::jni::getJavaExceptionForCppException(exception); + auto stackTrace = throwable->getStackTrace(); + std::string stackTraceStr = throwable->toString() + '\n'; + for (int i = 0; i < stackTrace->size(); ++i) { + auto frame = stackTrace->getElement(i); + stackTraceStr += frame->toString() + '\n'; + } + throw std::runtime_error(stackTraceStr); } }; From e3d9b336a9289370d8af7c7a7a1c41caca9c5e5b Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Fri, 14 Apr 2023 17:33:23 +0200 Subject: [PATCH 3/9] Add JSError with cause for NSExceptions --- .../platform/ios/ReactCommon/RCTTurboModule.mm | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm index b2974b803bbe1f..ab9c838949c6f8 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm @@ -211,14 +211,14 @@ static int32_t getUniqueId() return [callback copy]; } -static NSString *converNSExceptionToString(NSException *exception) +static NSString *converNSExceptionStackToString(NSException *exception) { NSMutableString *stack = [[NSMutableString alloc] init]; for (NSString* symbol in exception.callStackSymbols) { - [stack appendFormat:@"%@\u2028", symbol]; + [stack appendFormat:@"%@\n", symbol]; } - return [NSString stringWithFormat:@"%@\u2028%@\u2028%@\u2028", exception.name, exception.reason, stack]; + return stack; } namespace facebook { @@ -391,7 +391,17 @@ static int32_t getUniqueId() @try { [inv invokeWithTarget:strongModule]; } @catch (NSException *exception) { - throw std::string([converNSExceptionToString(exception) UTF8String]); + std::string reason = std::string([exception.reason UTF8String]); + jsi::Object cause(runtime); + cause.setProperty(runtime, "name", std::string([exception.name UTF8String])); + cause.setProperty(runtime, "message", reason); + cause.setProperty(runtime, "stack", std::string([converNSExceptionStackToString(exception) UTF8String])); + //TODO For release builds better would be use include callStackReturnAddresses + jsi::Value error = + runtime.global().getPropertyAsFunction(runtime, "Error") + .call(runtime, "Exception in HostFunction: " + reason); + error.asObject(runtime).setProperty(runtime, "cause", cause); + throw jsi::JSError(runtime, std::move(error)); } @finally { [retainedObjectsForInvocation removeAllObjects]; } From 954e720c66078c09773c7e9fb1df8350ca8d3681 Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Fri, 14 Apr 2023 19:49:20 +0200 Subject: [PATCH 4/9] fix typo --- .../core/platform/ios/ReactCommon/RCTTurboModule.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm index ab9c838949c6f8..e85921dab90281 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm @@ -211,7 +211,7 @@ static int32_t getUniqueId() return [callback copy]; } -static NSString *converNSExceptionStackToString(NSException *exception) +static NSString *convertNSExceptionStackToString(NSException *exception) { NSMutableString *stack = [[NSMutableString alloc] init]; for (NSString* symbol in exception.callStackSymbols) { @@ -395,7 +395,7 @@ static int32_t getUniqueId() jsi::Object cause(runtime); cause.setProperty(runtime, "name", std::string([exception.name UTF8String])); cause.setProperty(runtime, "message", reason); - cause.setProperty(runtime, "stack", std::string([converNSExceptionStackToString(exception) UTF8String])); + cause.setProperty(runtime, "stack", std::string([convertNSExceptionStackToString(exception) UTF8String])); //TODO For release builds better would be use include callStackReturnAddresses jsi::Value error = runtime.global().getPropertyAsFunction(runtime, "Error") From 4b69db010a4742a3b2e3cfd1c28d363e771a0fcd Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Mon, 17 Apr 2023 11:38:53 +0200 Subject: [PATCH 5/9] Add JSError with cause for Throwable --- .../android/ReactCommon/JavaTurboModule.cpp | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp index c7aab40c125793..fa076f46cce2ca 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp @@ -471,12 +471,36 @@ jsi::Value JavaTurboModule::invokeJavaMethod( auto exception = std::current_exception(); auto throwable = facebook::jni::getJavaExceptionForCppException(exception); auto stackTrace = throwable->getStackTrace(); - std::string stackTraceStr = throwable->toString() + '\n'; + + jsi::Array stackArray(runtime, stackTrace->size()); + std::string stackTraceStr; for (int i = 0; i < stackTrace->size(); ++i) { auto frame = stackTrace->getElement(i); stackTraceStr += frame->toString() + '\n'; + + jsi::Object frameObject(runtime); + frameObject.setProperty(runtime, "className", frame->getClassName()); + frameObject.setProperty(runtime, "fileName", frame->getFileName()); + frameObject.setProperty(runtime, "lineNumber", frame->getLineNumber()); + frameObject.setProperty(runtime, "methodName", frame->getMethodName()); + stackArray.setValueAtIndex(runtime, i, std::move(frameObject)); } - throw std::runtime_error(stackTraceStr); + + // TODO Better would be use getMessage() but its missing in fbjni interface + auto throwableString = throwable->toString(); + std::string name = throwableString.substr(0, throwableString.find(':')); + std::string message = throwableString.substr(throwableString.find(':') + 2, -1); + jsi::Object cause(runtime); + cause.setProperty(runtime, "name", name); + cause.setProperty(runtime, "message", message); + cause.setProperty(runtime, "stack", stackTraceStr); + cause.setProperty(runtime, "stackArray", std::move(stackArray)); + + jsi::Value error = + runtime.global().getPropertyAsFunction(runtime, "Error") + .call(runtime, "Exception in HostFunction: " + message); + error.asObject(runtime).setProperty(runtime, "cause", cause); + throw jsi::JSError(runtime, std::move(error)); } }; From e17d3f968179fb28c30dcf7ca31770da89b9cd47 Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Mon, 17 Apr 2023 20:22:10 +0200 Subject: [PATCH 6/9] Refactor cause, remove duplicate data, extract exception conversion to a function --- .../android/ReactCommon/JavaTurboModule.cpp | 70 +++++++++++-------- .../ios/ReactCommon/RCTTurboModule.mm | 38 +++++----- 2 files changed, 59 insertions(+), 49 deletions(-) diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp index fa076f46cce2ca..cb722ff9cb166a 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp @@ -401,6 +401,44 @@ jsi::Value convertFromJMapToValue(JNIEnv *env, jsi::Runtime &rt, jobject arg) { return jsi::valueFromDynamic(rt, result->cthis()->consume()); } +jsi::Value createJSRuntimeError(jsi::Runtime &runtime, const std::string& message) +{ + return runtime.global().getPropertyAsFunction(runtime, "Error").call(runtime, message); +} + +/** + * Creates JSError with current JS runtime stack and Throwable stack trace. + */ +jsi::JSError convertThrowableToJSError(jsi::Runtime &runtime, facebook::jni::local_ref throwable) +{ + auto stackTrace = throwable->getStackTrace(); + + jsi::Array stackElements(runtime, stackTrace->size()); + for (int i = 0; i < stackTrace->size(); ++i) { + auto frame = stackTrace->getElement(i); + + jsi::Object frameObject(runtime); + frameObject.setProperty(runtime, "className", frame->getClassName()); + frameObject.setProperty(runtime, "fileName", frame->getFileName()); + frameObject.setProperty(runtime, "lineNumber", frame->getLineNumber()); + frameObject.setProperty(runtime, "methodName", frame->getMethodName()); + stackElements.setValueAtIndex(runtime, i, std::move(frameObject)); + } + + // TODO Better would be use getMessage() but its missing in fbjni interface + auto throwableString = throwable->toString(); + std::string name = throwableString.substr(0, throwableString.find(':')); + std::string message = throwableString.substr(throwableString.find(':') + 2, -1); + jsi::Object cause(runtime); + cause.setProperty(runtime, "name", name); + cause.setProperty(runtime, "message", message); + cause.setProperty(runtime, "stackElements", std::move(stackElements)); + + jsi::Value error = createJSRuntimeError(runtime, "Exception in HostFunction: " + message); + error.asObject(runtime).setProperty(runtime, "cause", std::move(cause)); + return {runtime, std::move(error)}; +} + } // namespace jsi::Value JavaTurboModule::invokeJavaMethod( @@ -470,37 +508,7 @@ jsi::Value JavaTurboModule::invokeJavaMethod( } auto exception = std::current_exception(); auto throwable = facebook::jni::getJavaExceptionForCppException(exception); - auto stackTrace = throwable->getStackTrace(); - - jsi::Array stackArray(runtime, stackTrace->size()); - std::string stackTraceStr; - for (int i = 0; i < stackTrace->size(); ++i) { - auto frame = stackTrace->getElement(i); - stackTraceStr += frame->toString() + '\n'; - - jsi::Object frameObject(runtime); - frameObject.setProperty(runtime, "className", frame->getClassName()); - frameObject.setProperty(runtime, "fileName", frame->getFileName()); - frameObject.setProperty(runtime, "lineNumber", frame->getLineNumber()); - frameObject.setProperty(runtime, "methodName", frame->getMethodName()); - stackArray.setValueAtIndex(runtime, i, std::move(frameObject)); - } - - // TODO Better would be use getMessage() but its missing in fbjni interface - auto throwableString = throwable->toString(); - std::string name = throwableString.substr(0, throwableString.find(':')); - std::string message = throwableString.substr(throwableString.find(':') + 2, -1); - jsi::Object cause(runtime); - cause.setProperty(runtime, "name", name); - cause.setProperty(runtime, "message", message); - cause.setProperty(runtime, "stack", stackTraceStr); - cause.setProperty(runtime, "stackArray", std::move(stackArray)); - - jsi::Value error = - runtime.global().getPropertyAsFunction(runtime, "Error") - .call(runtime, "Exception in HostFunction: " + message); - error.asObject(runtime).setProperty(runtime, "cause", cause); - throw jsi::JSError(runtime, std::move(error)); + throw convertThrowableToJSError(runtime, throwable); } }; diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm index e85921dab90281..66bbf1faa22381 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm @@ -211,14 +211,27 @@ static int32_t getUniqueId() return [callback copy]; } -static NSString *convertNSExceptionStackToString(NSException *exception) +static jsi::Value createJSRuntimeError(jsi::Runtime &runtime, const std::string& message) { - NSMutableString *stack = [[NSMutableString alloc] init]; - for (NSString* symbol in exception.callStackSymbols) { - [stack appendFormat:@"%@\n", symbol]; - } + return runtime.global().getPropertyAsFunction(runtime, "Error").call(runtime, message); +} + +/** + * Creates JSError with current JS runtime and NSException stack trace. + */ +static jsi::JSError convertNSExceptionToJSError(jsi::Runtime &runtime, NSException *exception) +{ + std::string reason = [exception.reason UTF8String]; - return stack; + jsi::Object cause(runtime); + cause.setProperty(runtime, "name", [exception.name UTF8String]); + cause.setProperty(runtime, "message", reason); + cause.setProperty(runtime, "stackSymbols", convertNSArrayToJSIArray(runtime, exception.callStackSymbols)); + cause.setProperty(runtime, "stackReturnAddresses", convertNSArrayToJSIArray(runtime, exception.callStackReturnAddresses)); + + jsi::Value error = createJSRuntimeError(runtime, "Exception in HostFunction: " + reason); + error.asObject(runtime).setProperty(runtime, "cause", std::move(cause)); + return {runtime, std::move(error)}; } namespace facebook { @@ -387,21 +400,10 @@ static int32_t getUniqueId() TurboModulePerfLogger::asyncMethodCallExecutionStart(moduleName, methodNameStr.c_str(), asyncCallCounter); } - // TODO(T66699874) Should we guard this with a try/catch? @try { [inv invokeWithTarget:strongModule]; } @catch (NSException *exception) { - std::string reason = std::string([exception.reason UTF8String]); - jsi::Object cause(runtime); - cause.setProperty(runtime, "name", std::string([exception.name UTF8String])); - cause.setProperty(runtime, "message", reason); - cause.setProperty(runtime, "stack", std::string([convertNSExceptionStackToString(exception) UTF8String])); - //TODO For release builds better would be use include callStackReturnAddresses - jsi::Value error = - runtime.global().getPropertyAsFunction(runtime, "Error") - .call(runtime, "Exception in HostFunction: " + reason); - error.asObject(runtime).setProperty(runtime, "cause", cause); - throw jsi::JSError(runtime, std::move(error)); + throw convertNSExceptionToJSError(runtime, exception); } @finally { [retainedObjectsForInvocation removeAllObjects]; } From 847043eac5132d10f05b7e58fb3e3fbaa199bede Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Mon, 17 Apr 2023 21:38:31 +0200 Subject: [PATCH 7/9] Use dedicated method to get throwable name and message --- .../android/ReactCommon/JavaTurboModule.cpp | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp index cb722ff9cb166a..50527f6c28ec27 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp @@ -411,32 +411,36 @@ jsi::Value createJSRuntimeError(jsi::Runtime &runtime, const std::string& messag */ jsi::JSError convertThrowableToJSError(jsi::Runtime &runtime, facebook::jni::local_ref throwable) { - auto stackTrace = throwable->getStackTrace(); - - jsi::Array stackElements(runtime, stackTrace->size()); - for (int i = 0; i < stackTrace->size(); ++i) { - auto frame = stackTrace->getElement(i); - - jsi::Object frameObject(runtime); - frameObject.setProperty(runtime, "className", frame->getClassName()); - frameObject.setProperty(runtime, "fileName", frame->getFileName()); - frameObject.setProperty(runtime, "lineNumber", frame->getLineNumber()); - frameObject.setProperty(runtime, "methodName", frame->getMethodName()); - stackElements.setValueAtIndex(runtime, i, std::move(frameObject)); - } + auto stackTrace = throwable->getStackTrace(); + + jsi::Array stackElements(runtime, stackTrace->size()); + for (int i = 0; i < stackTrace->size(); ++i) { + auto frame = stackTrace->getElement(i); + + jsi::Object frameObject(runtime); + frameObject.setProperty(runtime, "className", frame->getClassName()); + frameObject.setProperty(runtime, "fileName", frame->getFileName()); + frameObject.setProperty(runtime, "lineNumber", frame->getLineNumber()); + frameObject.setProperty(runtime, "methodName", frame->getMethodName()); + stackElements.setValueAtIndex(runtime, i, std::move(frameObject)); + } - // TODO Better would be use getMessage() but its missing in fbjni interface - auto throwableString = throwable->toString(); - std::string name = throwableString.substr(0, throwableString.find(':')); - std::string message = throwableString.substr(throwableString.find(':') + 2, -1); - jsi::Object cause(runtime); - cause.setProperty(runtime, "name", name); - cause.setProperty(runtime, "message", message); - cause.setProperty(runtime, "stackElements", std::move(stackElements)); - - jsi::Value error = createJSRuntimeError(runtime, "Exception in HostFunction: " + message); - error.asObject(runtime).setProperty(runtime, "cause", std::move(cause)); - return {runtime, std::move(error)}; + jsi::Object cause(runtime); + auto getName = throwable->getClass()->getClass() + ->getMethod()>("getSimpleName"); + auto getMessage = throwable->getClass() + ->getMethod()>("getMessage"); + auto message = getMessage(throwable)->toStdString(); + cause.setProperty( + runtime, + "name", + getName(throwable->getClass())->toStdString()); + cause.setProperty(runtime,"message",message); + cause.setProperty(runtime, "stackElements", std::move(stackElements)); + + jsi::Value error = createJSRuntimeError(runtime, "Exception in HostFunction: " + message); + error.asObject(runtime).setProperty(runtime, "cause", std::move(cause)); + return {runtime, std::move(error)}; } } // namespace From 3a8279cb756764011ffb65efacbcd27ea5c0cd30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kry=C5=A1tof=20Wold=C5=99ich?= <31292499+krystofwoldrich@users.noreply.github.com> Date: Fri, 21 Apr 2023 13:37:47 +0200 Subject: [PATCH 8/9] Apply suggestions from code review Co-authored-by: Pieter De Baets --- .../core/platform/android/ReactCommon/JavaTurboModule.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp index 50527f6c28ec27..23b625c0c17512 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp @@ -427,9 +427,9 @@ jsi::JSError convertThrowableToJSError(jsi::Runtime &runtime, facebook::jni::loc jsi::Object cause(runtime); auto getName = throwable->getClass()->getClass() - ->getMethod()>("getSimpleName"); + ->getMethod()>("getName"); auto getMessage = throwable->getClass() - ->getMethod()>("getMessage"); + ->getMethod()>("getMessage"); auto message = getMessage(throwable)->toStdString(); cause.setProperty( runtime, @@ -511,7 +511,7 @@ jsi::Value JavaTurboModule::invokeJavaMethod( TMPL::asyncMethodCallFail(moduleName, methodName); } auto exception = std::current_exception(); - auto throwable = facebook::jni::getJavaExceptionForCppException(exception); + auto throwable = jni::getJavaExceptionForCppException(exception); throw convertThrowableToJSError(runtime, throwable); } }; From 1e7232ef00a4dbd0651185f46ee978d6853573d3 Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Fri, 21 Apr 2023 14:46:54 +0200 Subject: [PATCH 9/9] Fix format --- .../platform/android/ReactCommon/JavaTurboModule.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp index 23b625c0c17512..7834d62378d5d4 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp @@ -409,7 +409,7 @@ jsi::Value createJSRuntimeError(jsi::Runtime &runtime, const std::string& messag /** * Creates JSError with current JS runtime stack and Throwable stack trace. */ -jsi::JSError convertThrowableToJSError(jsi::Runtime &runtime, facebook::jni::local_ref throwable) +jsi::JSError convertThrowableToJSError(jsi::Runtime &runtime, jni::local_ref throwable) { auto stackTrace = throwable->getStackTrace(); @@ -431,11 +431,8 @@ jsi::JSError convertThrowableToJSError(jsi::Runtime &runtime, facebook::jni::loc auto getMessage = throwable->getClass() ->getMethod()>("getMessage"); auto message = getMessage(throwable)->toStdString(); - cause.setProperty( - runtime, - "name", - getName(throwable->getClass())->toStdString()); - cause.setProperty(runtime,"message",message); + cause.setProperty(runtime, "name", getName(throwable->getClass())->toStdString()); + cause.setProperty(runtime, "message", message); cause.setProperty(runtime, "stackElements", std::move(stackElements)); jsi::Value error = createJSRuntimeError(runtime, "Exception in HostFunction: " + message);