Skip to content

fix(browser): report the caller's line and column for browser-run compile errors - #356

Merged
ankitranjan7 merged 2 commits into
mainfrom
fix/browser-run-syntax-position
Aug 19, 2026
Merged

fix(browser): report the caller's line and column for browser-run compile errors#356
ankitranjan7 merged 2 commits into
mainfrom
fix/browser-run-syntax-position

Conversation

@ankitranjan7

Copy link
Copy Markdown
Contributor

Closes #353.

A program that fails to compile inside browser run was reported as
QuickJS promise rejected: invalid number literal with no position. The prefix
pointed at async plumbing rather than at the program, so readers audited
heredocs and await instead of the actual defect — an unescaped quote in a
string literal holding a URL.

Before / after

Real case from the task eval, a 2,361-character line:

✖  BROWSER_RUN_SYNTAX_ERROR: QuickJS promise rejected: invalid number literal
✖  Fix the browser-run JavaScript syntax and retry.
✖  BROWSER_RUN_SYNTAX_ERROR: invalid number literal at line 1, column 1215
  tput%3E%3Cscript%3Econst%20form%3Ddocument.querySelector('%23registration')%2Cdr
                                                             ^
✖  Your program failed to compile; the browser was never touched. A common cause
   is an unescaped quote when embedding a URL or HTML in a string literal — use
   double quotes or a template literal for values that contain apostrophes.

What changed

  • Compile the program before racing it, so a compile failure is no longer a
    rejected promise wearing a host stage prefix.
  • Report the caller's own line and column. new AsyncFunction(body) prepends two
    lines of wrapper, so those are subtracted — verified against QuickJS, which does
    supply lineNumber / columnNumber; they were simply being discarded.
  • Emit a windowed excerpt with a caret so a 2,000-character line stays readable.
  • Name the quoting cause in the hint.
  • quickjs-host.ts#toError no longer prefixes errors that already carry a
    BROWSER_RUN_ code.

Drive-by

runner.test.ts imported MemorySnapshotBaselineStore twice, so the file failed
to load and its 74 tests had never run. The duplicate is removed here; all 74
pass.

Verification

  • Reproduced the original failure against a local build, then confirmed the new
    output for both the minimal case and the real 2,361-character program.
  • New regression test pins the line, column, source excerpt, absent prefix, and
    hint — this also pins the AsyncFunction two-line offset against future
    quickjs-ng upgrades.
  • Unit suite: 2534 pass, 1 failure that is also present on main and unrelated
    (profile display, personal: connected v1.2.3). Baseline on main is 2460
    passing, so this adds 74 previously-dead tests.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

🟠 Maintainer review suggested — low confidence

The automated review could not reach a fully supported conclusion.

Limitations

  • The automated review returned an invalid structured result.

This review is advisory and does not block merging.

…pile errors

A program that fails to compile was surfaced as
"QuickJS promise rejected: invalid number literal" with no position, because
new AsyncFunction(source) runs inside the promise and its SyntaxError carried
lineNumber/columnNumber that were then discarded. The prefix pointed at async
plumbing rather than the program, so readers hunted heredocs and await instead
of the actual defect: an unescaped quote in a string literal holding a URL.

Compile the program before racing it, and turn a compile failure into a
BROWSER_RUN_SYNTAX_ERROR carrying the caller's own line and column (the
AsyncFunction wrapper adds two lines, so subtract them), a windowed excerpt
with a caret, and a hint naming the quoting cause. Errors that already carry a
BROWSER_RUN_ code keep their message instead of gaining a host stage prefix.

runner.test.ts imported MemorySnapshotBaselineStore twice, so the file failed
to load and its 74 tests never ran; the duplicate is removed here.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ankitranjan7
ankitranjan7 force-pushed the fix/browser-run-syntax-position branch from e9e3ae2 to 3997e54 Compare August 19, 2026 05:59
…rors (#358)

normalizeExecutionError matched /syntaxerror/i against any error reaching the
host, so a runtime JSON.parse failure in a perfectly valid program was reported
as BROWSER_RUN_SYNTAX_ERROR with a hint telling the reader to fix correct code.

Since compile failures now tag themselves at the point of compilation, the only
SyntaxErrors reaching this classifier are runtime ones. Drop the branch: a
runtime SyntaxError keeps its own name and message, exactly like the runtime
TypeErrors and RangeErrors that already flow through the generic path.

Closes #355

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
@ankitranjan7
ankitranjan7 merged commit 44f1c5f into main Aug 19, 2026
37 checks passed
@ankitranjan7
ankitranjan7 deleted the fix/browser-run-syntax-position branch September 1, 2026 12:41
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.

browser run: compile errors report no line, column, or source

1 participant