Preserve backtrace through JsError → JsValue → JsError round-trip#4609
Preserve backtrace through JsError → JsValue → JsError round-trip#4609jedel1043 merged 9 commits intoboa-dev:mainfrom
Conversation
|
@jedel1043 requesting review |
Test262 conformance changes
|
|
I recommend you to fix the issues in your code and make it pass the CI otherwise it can't be merged. |
|
@randomboi404 @jedel1043 done |
|
interesting. it appears that backtraces (maybe a feature) seems to differ on the CI... to avoid flakiness with source code changes in the Reproduced it. So:
|
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>
Collapse nested `if let` blocks into chained `let` conditions to satisfy the `clippy::collapsible_if` lint. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add backticks around type names in doc comment (clippy::doc_markdown) - Remove unnecessary hashes from raw string literals (clippy::needless_raw_string_hashes)
The `native-backtrace` feature (enabled via workspace feature unification from boa_cli) changes error output to include Rust source locations. Strip native location info before comparing so tests pass in both modes. Also add a sanity check test for context.eval() backtrace (relates to boa-dev#4475).
5455b07 to
5373239
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4609 +/- ##
==========================================
+ Coverage 47.24% 56.91% +9.66%
==========================================
Files 476 549 +73
Lines 46892 60129 +13237
==========================================
+ Hits 22154 34222 +12068
- Misses 24738 25907 +1169 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ding Consolidate backtrace tests from the separate integration test file (core/engine/tests/errors.rs) into the in-crate unit test module (builtins::error::tests) for better access to internal types. Remove duplicate `let path` binding that caused an unused variable warning.
|
@jedel1043 should be ready to merge now. |
Backtrace tests exercise JsError behavior, not the Error builtin, so they belong in the error module. Convert error.rs to a module directory and add the backtrace tests there. Keep builtin-specific tests (error_to_string, error_names, error_lengths) in builtins/error.
jedel1043
left a comment
There was a problem hiding this comment.
Very nice, thank you for the fix!
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