Skip to content

fix(extension): clamp Position character to avoid negative values#768

Merged
yury-s merged 1 commit into
microsoft:mainfrom
yury-s:fix-negative-position-column
Apr 18, 2026
Merged

fix(extension): clamp Position character to avoid negative values#768
yury-s merged 1 commit into
microsoft:mainfrom
yury-s:fix-negative-position-column

Conversation

@yury-s
Copy link
Copy Markdown
Member

@yury-s yury-s commented Apr 18, 2026

Reference microsoft/playwright#40226

Summary

Users report the extension crashes with "Illegal argument: character must be non-negative" after a recent Windows update (25H2 / build 26200.8246), leaving no tests visible. The underlying trigger is a connect ETIMEDOUT ::1:<port> when the extension fails to connect to its spawned Playwright test server (likely OS-level IPv6/loopback change). That's a separate root cause — this PR is about the crash that follows.

When listFiles() throws, TestModel._listFiles synthesizes a config error with location: { file: configFile, line: 0, column: 0 }. Downstream, TestTree._syncConfigErrors (and Extension._asPosition) did column - 1 without clamping — producing character = -1, which VSCode's Position constructor rejects. Six uncaught errors per activation, one per surfaced error location.

  • Clamp column - 1 the same way line - 1 was already clamped, at all three call sites that convert a Playwright error location into a Position.
  • Tighten the Position mock in tests to reject negative line/character (matching real VSCode behavior), so any future regression is caught by the suite.
  • Add a focused test in problems.spec.ts covering column = 0.

The underlying ETIMEDOUT is not addressed here — this fix just keeps the extension usable (diagnostic is shown, tests remain discoverable) instead of crashing silently when it happens.

Playwright reports error locations with column 0 when a stack frame has
no column info (the fallback in playwright-core's stackTrace parser).
The extension converted these via `column - 1`, producing -1, and VSCode's
Position constructor throws "Illegal argument: character must be non-negative",
surfacing as multiple uncaught errors on activation.

Clamp `column - 1` the same way `line - 1` is already clamped, and update
the Position mock to reject negatives so regressions are caught by the suite.
@yury-s yury-s merged commit ef7c3b4 into microsoft:main Apr 18, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants