Skip to content

fix(manifest): TOML parse errors report filename:line:col#84

Merged
hyperpolymath merged 1 commit into
mainfrom
fix/toml-span-aware-errors
May 14, 2026
Merged

fix(manifest): TOML parse errors report filename:line:col#84
hyperpolymath merged 1 commit into
mainfrom
fix/toml-span-aware-errors

Conversation

@hyperpolymath
Copy link
Copy Markdown
Owner

Summary

Per V-L3-H1: TOML parse errors were just wrapped in anyhow::Context("Failed to parse manifest: <path>"). The toml crate already provides span info via toml::de::Error::span(); extract it and emit path:line:col: <toml message> (editor-standard format).

Closes

Test plan

  • cargo clippy --all-targets -- -D warnings clean
  • cargo test --lib --bins 43/43 (1 new: malformed_manifest_reports_line_and_column)
  • Test writes a broken manifest, asserts error contains path + :N:M: span

Closes #55.

`load_manifest` was just wrapping the underlying `toml::de::Error` in
`anyhow::Context("Failed to parse manifest: <path>")`. The `toml` crate
already carries span information per `toml::de::Error::span()`, but
it was being thrown away. Editors couldn't jump to the offending line.

Extract the span, convert the byte offset to a 1-based `(line, col)`
via a small helper that counts newlines, and format as the editor-
standard `<path>:<line>:<col>: <toml message>`. The conversion uses
`bytes()` rather than chars for cheap O(n) scanning of the prefix; the
result is a UTF-8 *byte* column, which is what most editors and IDE
language servers expect for jump-to-position.

Test `malformed_manifest_reports_line_and_column` writes a manifest
with a broken assignment on line 3 and asserts the error string
contains both the manifest path and a `:N:M:` span indicator.

`cargo clippy --all-targets -- -D warnings` clean; 43 unit tests pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@hyperpolymath hyperpolymath merged commit 9ed78f4 into main May 14, 2026
16 of 18 checks passed
@hyperpolymath hyperpolymath deleted the fix/toml-span-aware-errors branch May 14, 2026 14:56
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.

V-L3-H1: span-aware TOML parse errors (filename:line:col)

1 participant