Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Consider Source Map For Stack Traces #2176

Open
hediet opened this issue Feb 21, 2025 · 3 comments
Open

Consider Source Map For Stack Traces #2176

hediet opened this issue Feb 21, 2025 · 3 comments

Comments

@hediet
Copy link
Member

hediet commented Feb 21, 2025

Sometimes, I see stack traces in the debug output:

Code_-_Insiders_k0P4UJJ0Ts

  ERR Cannot read properties of undefined (reading 'read'): TypeError: Cannot read properties of undefined (reading 'read')
    at Derived._computeFn (http://localhost:3000/src/vs/editor/contrib/inlineCompletions/browser/view/inlineEdits/inlineEditsView.ts?t=1740093639452:81:132)
    at Derived._recomputeIfNeeded (http://localhost:3000/src/vs/base/common/observableInternal/derived.ts?t=1740052750953:213:27)
    at Derived.get (http://localhost:3000/src/vs/base/common/observableInternal/derived.ts?t=1740052750953:191:14)
    at Derived.readObservable (http://localhost:3000/src/vs/base/common/observableInternal/derived.ts?t=1740052750953:322:30)
    at Derived.read (http://localhost:3000/src/vs/base/common/observableInternal/base.ts:27:21)
    at Derived._computeFn (http://localhost:3000/src/vs/base/common/observableInternal/base.ts:55:27)
    at Derived._recomputeIfNeeded (http://localhost:3000/src/vs/base/common/observableInternal/derived.ts?t=1740052750953:213:27)
    at Derived.get (http://localhost:3000/src/vs/base/common/observableInternal/derived.ts?t=1740052750953:191:14)
    at Derived.readObservable (http://localhost:3000/src/vs/base/common/observableInternal/derived.ts?t=1740052750953:322:30)
    at Derived.read (http://localhost:3000/src/vs/base/common/observableInternal/base.ts:27:21)

However, it is difficult to act on them, as they refer to the out source, and not the original typescript files.
It would be very helpful if the source map was considered for these stacktraces.

Some implementation ideas:

  1. Detect stack-like strings and rewrite them before they are written to the debug console
  2. Implement a link detector in the debug console that opens the source mapped location (e.g. ./src/main.ts) instead of the link directly (http://localhost:3000/src/main.ts)
  3. Add [[Location]] to the view when an Error is viewed, similar to functions (though this wouldn't work out of the box, as not the error object is logged, but the error string).
    Code_-_Insiders_FX3EiwO6FY
  4. Register a cdp binding so that the debugee can translate stack traces on their own (if the binding is present). Additionally, the debugger could inject JS code that patches Error.stack to automatically consider stack traces
@hediet hediet changed the title Consider Source Map For StackTraces Consider Source Map For Stack Traces Feb 21, 2025
@connor4312
Copy link
Member

connor4312 commented Feb 21, 2025

We do this but only if we're logging an Error object. We can probably be more aggressive

output = await thread.replacePathsInStackTrace(output);

@hediet
Copy link
Member Author

hediet commented Feb 21, 2025

Ah yes, I can verify that console.log(new Error()) works, but console.log(new Error().stack) not!

Maybe we can fix onUnhandledError in vscode to log the error object instead of the stack trace.

@connor4312
Copy link
Member

I'm good making that check more permissive too. PR welcome :)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants