Repository navigation
fix(codemode): report parse errors with a location and a hint - #59834
Conversation
There was a problem hiding this comment.
Looks good. On the base, CodeMode.execute returned acorn's raw messages (Unexpected token (1:6), 'import' and 'export' may appear only with 'sourceType: module' (1:0)) with no location. With this change the same programs report SyntaxError: … (line L, col C) with a 1-based location, imports and exports get the dedicated message, and non-acorn failures while parsing (deep nesting) still report the nesting-depth error. In packages/codemode, bun test and tsc --noEmit pass, as do core's codemode/execute tests.
Public API: unchanged. Only the diagnostic message text changes, plus the already-typed optional location field.
No concerns.
There was a problem hiding this comment.
The new commit is fine. It removes the TypeScript clause from the general parse-error hint and updates the matching tests. I ran the reproduction from #50577 with a simulated model on the base and on this head. The base returns acorn's raw messages. With the PR, every error has a 1-based (line L, col C) location and the shorter hint, and imports get the dedicated message. errors.test.ts and tsc --noEmit pass.
Public API: unchanged.
No new concerns.


Fixes #50577
Problem
When Code Mode can't parse a program, the model gets acorn's raw message: no
location, acorn's own(line:col)format with a 0-based column, and for imports a hint about an internal parser option. Every other Code Mode error reads likeTypeError: ... (line 1, col 15).Change
executeProgramnow catches acorn'sSyntaxErrorand returns aParseErrorwith a 1-basedlocationand the same(line L, col C)suffix as other errors. Imports and exports get a dedicated message. Everything else keeps acorn's text and adds a short note on what code has to look like. Anything else thrown while parsing (like a stack overflow on deeply nested input) goes down the same path as before.What the model sees (copied from a run through core's
executetool):const = 1Unexpected token (1:6)SyntaxError: Unexpected token. Code must be plain JavaScript written as a program body. (line 1, col 7)import x from "y"'import' and 'export' may appear only with 'sourceType: module' (1:0)SyntaxError: Imports and exports aren't available. Call tools through `tools` and use the built-in globals. (line 1, col 1)const x: number = 1Unexpected token (1:7)SyntaxError: Unexpected token. Code must be plain JavaScript written as a program body. (line 1, col 8)The structured diagnostic also carries
location: { line, column }now.formatLocationtakes a location instead of a node so both paths share it. No public types changed.Out of scope
Unsupported syntax that parses fine (classes, getters and setters, and so on) already reports
UnsupportedSyntaxwith its own hint. I left that alone.Verification
From
packages/codemode, afterbun run script/sync-test262.ts ~/development/test262:bun run typecheck: no type errorsbun run typecheck:tsc: cleanbun test: 14795 pass, 1678 skip, 0 fail (14791 pass and the same skips before the change; test262 negative parse tests still pass)From
packages/core:bun run script/test.ts test/codemode test/tool-execute.test.ts: 30 pass, 0 failFrom the repo root:
bun run check: passed