Extension host: use native source maps in development hosts - #339169
Goga Koreli (gogakoreli) wants to merge 2 commits into
Conversation
Enable Node's source-map support before importing the extension host. Keep the error-attribution walk and delegate stack formatting to the previous formatter when native source maps are enabled. Preserve the existing output for source-map-disabled hosts and custom formatter wrapping. Add isolated subprocess tests for real mapped frames, runtime-error and telemetry attribution, custom formatters, runtime toggling, and bootstrap opt-in behavior. Related to microsoft#145473 and microsoft#238469. X-AI-Prompt: Add dev-host-only native source maps with regression tests and raise a VS Code PR. X-AI-Tool: OpenAI coding assistant
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Formatter receiver handling is incorrect, and native formatting currently duplicates avoidable stack-processing work.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Enables native source-map formatting for local extension-development hosts while retaining extension error attribution.
Changes:
- Activates Node source maps during extension-host bootstrap.
- Delegates stack formatting to Node when enabled.
- Adds subprocess regression coverage.
| File | Description |
|---|---|
src/bootstrap-fork.ts |
Enables native source maps before host loading. |
src/vs/workbench/api/common/extensionHostMain.ts |
Preserves native formatting during attribution. |
src/vs/workbench/api/test/node/extensionHostSourceMaps.test.ts |
Tests mapping, attribution, formatters, and bootstrap flags. |
src/vs/workbench/services/extensions/electron-browser/localProcessExtensionHost.ts |
Enables source maps for development hosts. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| const result = `${error.name || 'Error'}: ${error.message || ''}${stackTraceMessage}`; | ||
| const sourceMapsEnabled = (globalThis as { process?: { sourceMapsEnabled?: boolean } }).process?.sourceMapsEnabled === true; | ||
| const result = sourceMapsEnabled && defaultPrepareStackTrace | ||
| ? defaultPrepareStackTrace(error, stackTrace) |
There was a problem hiding this comment.
Fixed in e81fe03. The captured formatter is now called with Error as its receiver, and the before/after formatter tests use receiver-sensitive functions. I also removed the assertions by inferring the captured hook and contextually typing the wrapper from typeof Error.prepareStackTrace.
| const sourceMapsEnabled = (globalThis as { process?: { sourceMapsEnabled?: boolean } }).process?.sourceMapsEnabled === true; | ||
| const result = sourceMapsEnabled && defaultPrepareStackTrace | ||
| ? defaultPrepareStackTrace(error, stackTrace) | ||
| : `${error.name || 'Error'}: ${error.message || ''}${stackTraceMessage}`; |
There was a problem hiding this comment.
Fixed in e81fe03. Formatter selection now happens before the attribution walk, and fallback toString()/concatenation only runs when needed. Added a regression that checks zero fallback rendering calls while runtime-error and telemetry attribution still work; it fails against the previous implementation.
Infer the captured Error.prepareStackTrace hook and contextually type the wrapper from its declared callback contract instead of asserting a narrower V8CallSite signature. Preserve Error as the captured formatter's receiver. Select the formatter before the attribution walk and skip unused fallback string rendering. Add regression coverage for receiver-sensitive formatters and zero fallback rendering calls while preserving runtime attribution. X-AI-Prompt: Address reviewer feedback with inferred formatter types and regression tests. X-AI-Tool: OpenAI coding assistant
|
Goga Koreli (@gogakoreli) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
1 similar comment
|
Goga Koreli (@gogakoreli) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|


Summary
Related to #145473 and #238469. This is a local extension-development host first step, not a claim to resolve the broader request for source-mapped crash reports from shipped extensions.
A bundled extension can ship a valid source map and still produce generated-file locations in its error stacks. There are two independent pieces to address:
Error.prepareStackTraceformatter when native source maps are enabled. Building the stack fromCallSite.toString()bypasses Node's mapped formatting.This PR uses
module.setSourceMapsSupport(true)and adds no dependency,Module._loadinterception, or extension API. The flag is set byNativeLocalProcessExtensionHostonly for development hosts. With source maps disabled, the existing formatter and its tab indentation remain unchanged. Existing handling of formatters installed by extensions remains in place.The formatter composition follows Node's documented guidance and the pattern used by Babel. The captured hook is inferred, and the wrapper is contextually typed from
typeof Error.prepareStackTrace, rather than asserting compatibility with a narrower call-site interface. Delegation preserves theErrorreceiver, and the native path skips unused fallback string rendering while retaining attribution.Before / after
The new isolated-process regression fixture has a real CommonJS module with an external source map. Paths below are shortened; this is a test fixture, not a screenshot from a fully launched editor.
Before (existing host formatter, even with native maps enabled):
After (native formatter preserved):
The fixture deliberately uses a single mapping segment to make the expected source location deterministic. The test also verifies that the same error reaches
$onExtensionRuntimeErrorand extension telemetry with the correct extension identifier and stack. It does not just assert a fabricated formatter string.Regression coverage
Nine new cases run in separate child processes because the host makes
Error.prepareStackTracenon-configurable:Errorreceiver.toString()calls when a formatter is selected, with attribution preserved.false, andtrue.I also ran the existing seven formatter-wrapping/re-wrapping tests for #184926.
To check the tests are sensitive to the change, I temporarily removed the proposed formatter delegation and bootstrap activation while retaining the original eight tests. Three cases failed: native mapping, the pre-installed formatter case, and bootstrap activation. Restoring the implementation made the suite pass.
For the review follow-up, I strengthened the custom-formatter cases to check the receiver and added an independently instrumented fallback-rendering case. Against the initial PR implementation, these exposed two failures: an incorrect receiver and one unnecessary fallback rendering call. Both pass after the revision.
Local validation
Public
microsoft/vscodesource based on1f6488722c942d1d7528a7d949769a69e4a557c3, macOS arm64:npm run transpile-client— passed.npm run typecheck-client— passed.--max-warnings 0— passed.scripts/test.sh.npm run valid-layers-check— passed.git-secretswith AWS patterns on all four contribution files — passed.git diff --check— passed.Commands:
The subprocess cases use Electron-as-Node when launched from the Electron test runner. A full UI/utility-process extension-host launch, Windows/Linux validation, and a representative startup/stack-formatting performance benchmark are not yet completed. Opening as a draft to make that validation scope explicit and discuss whether this is a useful first step.
Scope and prior work
source-map-supportfor stack trace formatting inextensionHostdebugging #238469, not a continuation of that PR or a claim to its authorship.file:URL error-attribution behavior is a separate concern and is intentionally not included.Would the maintainers be open to this dev-host-only first step? Happy to adjust the scope based on guidance.
Prepared with AI assistance. The local automated checks are listed above; maintainer review is still required.