Repository navigation
Error has a stack: where it was made, as V8 says it - #132
Merged
Merged
Conversation
- `new Error()` captures the return addresses it was made from (wrappers/os.cpp tslang_stack_capture: on Windows unwound by the function tables, which the JIT's code has too; on Linux _Unwind_Backtrace); in the DLL or shared object the JIT loads, the library's own frames are left out - `stack`, read: toString()'s first line, then ` at f (a.ts:7)` lines, at most 10. Named by the program's runtime (the compiler's `__tslang_stack_text`: the executable's runtime, or tslang for the JIT), as the report of an uncaught exception names frames; a runtime without it (an older compiler's) leaves `module+0xoffset` lines. It may be given another text. - wasm has no frames: its `stack` is the first line alone (lib.wasm.ts) - the platform layers give core.ts error_stack_capture / error_stack_text (core/core.os.d.ts) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Error.stack, the library side. The compiler side is ASDAlexander77/TypeScriptCompiler#1081.new Error()records the return addresses it was made from (wrappers/os.cpp,tslang_stack_capture). On Windows the stack is unwound by the function tables, as the uncaught-exception report walks it:RtlCaptureStackBackTracestops at the JIT's code, which no image holds. On Linux it uses_Unwind_Backtrace. In the DLL or shared object the JIT loads, the library's own frames are left out.stackgivestoString()'s line, thenat f (a.ts:7)lines, at most 10. The frames are named by the program's runtime (the compiler's__tslang_stack_text, found in the executable's exports on Windows, or as a weak symbol on Linux), the same way the uncaught report names frames. A runtime without it (the released compiler) leavesmodule+0xoffsetlines. The text is made the first timestackis read, and may be replaced.stackis the first line alone (lib.wasm.ts), with no new host import.core.tserror_stack_capture/error_stack_text(core/core.os.d.ts).Testing
tests/error_stack.ts, which checks the shape: the first line,atlines, at most 10, and thatstackcan be assigned. It passes under gc, rc, none and own, JIT and exe, on Windows with the compiler of #1081, and on Linux (WSL) and Windows with the released compiler (fallback lines). It prints nothing with "Error" in it, whichtests.shtreats as a failure.at inner / at outer / at main); an exe without--dishowsprogram.exe+0x…up tomain.🤖 Generated with Claude Code