- 
                Notifications
    You must be signed in to change notification settings 
- Fork 24.9k
POC: Mixed stack traces for Android and iOS Turbo Modules #36925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
a5dec1b
              6a721fa
              e3d9b33
              954e720
              4b69db0
              e17d3f9
              847043e
              3a8279c
              1e7232e
              956bf59
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -468,7 +468,39 @@ jsi::Value JavaTurboModule::invokeJavaMethod( | |
| } else { | ||
| TMPL::asyncMethodCallFail(moduleName, methodName); | ||
| } | ||
| throw; | ||
| auto exception = std::current_exception(); | ||
| auto throwable = facebook::jni::getJavaExceptionForCppException(exception); | ||
|         
                  krystofwoldrich marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| 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)); | ||
| } | ||
| }; | ||
|  | ||
|  | ||
Uh oh!
There was an error while loading. Please reload this page.