-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Fix LogBox parsing for cross-runtime jsi::JSErrors #55994
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -380,13 +380,40 @@ void RuntimeScheduler_Modern::executeTask( | |||||||||||
| task.callback = result.getObject(runtime).getFunction(runtime); | ||||||||||||
| } | ||||||||||||
| } catch (jsi::JSError& error) { | ||||||||||||
| onTaskError_(runtime, error); | ||||||||||||
| reportError(runtime, error); | ||||||||||||
| } catch (std::exception& ex) { | ||||||||||||
| jsi::JSError error(runtime, std::string("Non-js exception: ") + ex.what()); | ||||||||||||
| onTaskError_(runtime, error); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| void RuntimeScheduler_Modern::reportError( | ||||||||||||
| jsi::Runtime& runtime, | ||||||||||||
| jsi::JSError& error) const { | ||||||||||||
| try { | ||||||||||||
| auto errorCtor = | ||||||||||||
| runtime.global().getPropertyAsFunction(runtime, "Error"); | ||||||||||||
| auto errorObj = | ||||||||||||
| errorCtor | ||||||||||||
| .callAsConstructor( | ||||||||||||
| runtime, | ||||||||||||
| jsi::String::createFromUtf8(runtime, error.getMessage())) | ||||||||||||
| .getObject(runtime); | ||||||||||||
| errorObj.setProperty( | ||||||||||||
| runtime, | ||||||||||||
| "stack", | ||||||||||||
| jsi::String::createFromUtf8(runtime, error.getStack())); | ||||||||||||
| jsi::JSError localError( | ||||||||||||
| jsi::Value(std::move(errorObj)), | ||||||||||||
| error.getMessage(), | ||||||||||||
| error.getStack()); | ||||||||||||
| onTaskError_(runtime, localError); | ||||||||||||
| } catch (...) { | ||||||||||||
| jsi::JSError fallbackError(runtime, error.getMessage()); | ||||||||||||
|
||||||||||||
| jsi::JSError fallbackError(runtime, error.getMessage()); | |
| jsi::JSError fallbackError( | |
| runtime, | |
| error.getMessage(), | |
| error.getStack()); |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -46,8 +46,15 @@ class StubErrorUtils : public jsi::HostObject { | |||||||||
| name, | ||||||||||
| 1, | ||||||||||
| [this]( | ||||||||||
| jsi::Runtime &runtime, const jsi::Value &, const jsi::Value *arguments, size_t) noexcept -> jsi::Value { | ||||||||||
| jsi::Runtime &runtime, const jsi::Value &, const jsi::Value *arguments, size_t count) noexcept -> jsi::Value { | ||||||||||
| reportFatalCallCount_++; | ||||||||||
| if (count > 0 && arguments[0].isObject()) { | ||||||||||
| auto obj = arguments[0].getObject(runtime); | ||||||||||
| auto msgVal = obj.getProperty(runtime, "message"); | ||||||||||
| if (msgVal.isString()) { | ||||||||||
| lastReportedMessage_ = msgVal.getString(runtime).utf8(runtime); | ||||||||||
|
Comment on lines
48
to
+55
|
||||||||||
| } | ||||||||||
| } | ||||||||||
|
Comment on lines
50
to
+57
|
||||||||||
| return jsi::Value::undefined(); | ||||||||||
| }); | ||||||||||
| } | ||||||||||
|
|
@@ -60,8 +67,14 @@ class StubErrorUtils : public jsi::HostObject { | |||||||||
| return reportFatalCallCount_; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| const std::string &getLastReportedMessage() const | ||||||||||
| { | ||||||||||
| return lastReportedMessage_; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private: | ||||||||||
| int reportFatalCallCount_; | ||||||||||
| std::string lastReportedMessage_; | ||||||||||
|
Comment on lines
76
to
+77
|
||||||||||
| int reportFatalCallCount_; | |
| std::string lastReportedMessage_; | |
| int reportFatalCallCount_{0}; | |
| std::string lastReportedMessage_{}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback path reconstructs a
jsi::JSErrorwith only the message, which discardserror.getStack()even though it is already available and safe. Consider using theJSError(Runtime&, message, stack)constructor in the fallback to preserve the original stack trace when Error reconstruction fails.