Preserve backtrace through JsError → JsValue → JsError round-trip#4609
Open
AlbertMarashi wants to merge 2 commits intoboa-dev:mainfrom
Open
Preserve backtrace through JsError → JsValue → JsError round-trip#4609AlbertMarashi wants to merge 2 commits intoboa-dev:mainfrom
AlbertMarashi wants to merge 2 commits intoboa-dev:mainfrom
Conversation
Errors caught by internal exception handlers (e.g. async module evaluation) lost their backtrace when going through promise rejection, because the backtrace lived only on the JsError and was discarded during conversion to JsValue. - Store the backtrace on the Error object in `JsError::into_opaque` (both Native and Opaque variants) so it survives the round-trip - Recover the backtrace in `JsError::from_opaque` - Move backtrace capture in `handle_error` before the exception handler check so catchable errors also get a backtrace - Add regression tests for implicit TypeError, nested calls, and explicit throw Closes boa-dev#4608 Supersedes boa-dev#4607 Co-authored-by: Cursor <cursoragent@cursor.com>
Author
|
@jedel1043 requesting review |
Test262 conformance changes
|
Contributor
|
I recommend you to fix the issues in your code and make it pass the CI otherwise it can't be merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #4608
Supersedes #4607
JsError → JsValue → JsErrorround-trip via promise rejectionErrorobject inJsError::into_opaque(bothNativeandOpaquevariants) and recovers it inJsError::from_opaquehandle_errorbefore the exception handler check, so catchable errors also get a backtrace before being intercepted by internal handlersDetails
Previously, the backtrace was only captured for uncatchable errors (inside
if !err.is_catchable()) and for catchable errors that reachedhandle_throw(). Errors intercepted by internal handlers (e.g. the module async wrapper) were stored aspending_exceptionbefore either path could capture a backtrace. When these errors were later converted toJsValuefor promise rejection, the backtrace was lost entirely.This PR:
handle_error, before the exception handler checkErrorobject duringinto_opaque(for bothRepr::NativeandRepr::Opaqueerrors) so it survives conversion toJsValuefrom_opaqueby reading it back from theErrorobjectThis approach was suggested by @jedel1043 in #4607 — extending the
Errortype with abacktracefield rather than injecting positions, which would be incorrect with nestedtryblocks.Test plan
test_call_error_preserves_backtrace— callsundefined()at module top level, verifies backtrace with exact string matchtest_nested_call_error_preserves_backtrace— nestedfoo → baz → import.meta.non_existent(), verifies full multi-frame backtracetest_explicit_throw_preserves_backtrace— explicitthrow new Error("test")inside a function, verifies backtrace frames are presentMade with Cursor