Skip to content

fix(module-runner): prevent crash on negative column in stacktrace#21585

Open
AriPerkkio wants to merge 2 commits intovitejs:mainfrom
AriPerkkio:fix/module-runner-col-negative-crash
Open

fix(module-runner): prevent crash on negative column in stacktrace#21585
AriPerkkio wants to merge 2 commits intovitejs:mainfrom
AriPerkkio:fix/module-runner-col-negative-crash

Conversation

@AriPerkkio
Copy link
Contributor

@AriPerkkio AriPerkkio commented Feb 7, 2026

On Vite's side the root cause is as number, as CallSite can return null in line/col.

@AriPerkkio AriPerkkio marked this pull request as ready for review February 7, 2026 12:08
@AriPerkkio

This comment was marked as resolved.

const line = frame.getLineNumber() as number
const column = (frame.getColumnNumber() as number) - 1
const line = frame.getLineNumber() ?? 0
const column = (frame.getColumnNumber() ?? 1) - 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix does not prevent negative columns in all cases. When getColumnNumber() returns 0 (a valid non-nullish value), the result is still -1 because the nullish coalescing operator (??) only handles null or undefined, not 0. This means negative columns can still occur, contradicting the PR's stated purpose.

To actually prevent negative columns, the code should be:

const column = Math.max(0, (frame.getColumnNumber() ?? 1) - 1)
Suggested change
const column = (frame.getColumnNumber() ?? 1) - 1
const column = Math.max(0, (frame.getColumnNumber() ?? 1) - 1)

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@AriPerkkio AriPerkkio marked this pull request as draft February 7, 2026 18:37
Comment on lines +190 to +191
// Without the fix this causes unhandler error that cannot be caught inside the test case
await runner.import('/fixtures/a.ts')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

@AriPerkkio AriPerkkio marked this pull request as ready for review February 7, 2026 20:32
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.

ModuleRunner crashing when negative columns in stacktraces

1 participant