Skip to content

Show the source file, line and column in CLI errors - #2208

Merged
nicolas-abril merged 1 commit into
bendlang:mainfrom
sebastian-griego:fix/cli-error-source-location
Nov 23, 2026
Merged

nicolas-abril merged 1 commit into
bendlang:mainfrom
sebastian-griego:fix/cli-error-source-location

Conversation

@sebastian-griego

Copy link
Copy Markdown
Contributor

When an imported module has an error, the CLI shows the definition and underlines the token. A developer reading the build log still has to find the file. For example, a typo in lib/price.bend previously gave only Location: total and the excerpt.

The CLI now appends the canonical source path and one-based line and column. The example produces this location.

--> /project/lib/price.bend:4:12

The CLI uses the files the loader already tracked. An error in an import statement points to the statement in the importing file. The batch --checkup format stays compatible with existing test fixtures.

Verification

  • The new regression covers an entry-file error, an imported definition, and a missing dependency. It failed on the base commit and passed with this change through the source CLI, the compiled CLI, and emitted JavaScript.
  • All 518 existing error snapshots with a source location matched through --checkup.
  • All 136 bend-lint tests passed. The repository gate passed all 56 checks.
  • TypeScript 7.0.2 reported the same 10 diagnostics on this branch and the base commit.

@YidaWeng YidaWeng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I ran this on the PR head (03151a49) from a clean worktree.

  • bun gates/repo.ts -> PASS: 56 / 56.
  • bun bend2/main.ts tests/io/cli_source_location.bend -> 0.
  • -o cli_source_location.js && bun cli_source_location.js -> 0.
  • Manual checks: entry-file error -> main.bend:4:3; missing import -> importer main2.bend:1:8; error two imports deep -> b.bend:4:3. All correct.

Two small notes, neither blocking:

  1. The column is a UTF-16 code-unit offset, not a grapheme/visual column. For "🙂" ++ nope the CLI prints :4:11, which matches the existing caret position but is one past the visual column. If that is intended, a sentence in the PR or guide would help.
  2. book_location falls back to files.find(([, ns]) => ns === null) when the first match misses. With two files that fail to load, the reverse-order seen entry could name the wrong one. The three covered cases pass, but a test with two broken imports, or matching span.file directly, would pin it down.

I did not rerun the 518 snapshot set; the new regression and the repository gate pass. The seen threading and the cli_publish signature look complete (only one cli_publish caller), and the --checkup fixtures are untouched.

@nicolas-abril nicolas-abril self-assigned this Nov 23, 2026
@nicolas-abril
nicolas-abril merged commit 966bbb7 into bendlang:main Nov 23, 2026
1 check passed
nicolas-abril added a commit to nicolas-abril/bend that referenced this pull request Nov 24, 2026
, bendlang#2224-bendlang#2226, bendlang#2231, bendlang#2285, bendlang#2286, bendlang#2288 and others)

One conflict, in emit_unfold: bendlang#2288 annotates an unfolded call's lets with
the argument types instantiated by the earlier arguments; bendlang#2162's deep unfold
keeps its arguments unannotated there and annotates them the same way after
folding (its type walk renamed D, beside bendlang#2288's T). Both kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

3 participants