Skip to content

Fix TOML parse error locations#4098

Open
goutamadwant wants to merge 2 commits into
facebook:mainfrom
goutamadwant:fix-toml-error-location
Open

Fix TOML parse error locations#4098
goutamadwant wants to merge 2 commits into
facebook:mainfrom
goutamadwant:fix-toml-error-location

Conversation

@goutamadwant

Copy link
Copy Markdown
Contributor

Summary

Fixes #4060

This fixes TOML parse diagnostics so invalid config values point at the offending value instead of the start of the file.

The config parser now keeps usable TOML span information and adjusts broad serde validation spans to the matching TOML value span when possible. The playground now uses the same config parser and reports the derived range instead of hardcoding line 1, column 1.

Test Plan

  • cargo test -p pyrefly_config
  • cargo test -p pyrefly test_config_toml_parse_error_range -- --nocapture
  • cargo fmt --all -- --check

@github-actions

This comment has been minimized.

@NathanTempest NathanTempest 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.

Thanks @goutamadwant for this clean fix. Nice that it fails safe (falls back to the original span when a better one can't be derived) and that both the config-crate and playground tests pin the corrected location.

One follow-up worth considering (non-blocking): the span adjustment recovers the key/value by parsing toml_edit's error message text (in key.path, invalid type: string "…"), which is coupled to toml_edit's wording and could silently stop adjusting on a version bump. It degrades safely, so it's fine to land, but longer-term a toml::Spanned/serde_spanned-based approach (or reconstructing a toml_edit error with the adjusted span rather than the hand-rolled renderer) would be more robust.

@NathanTempest NathanTempest self-assigned this Jul 14, 2026
@github-actions github-actions Bot added size/l and removed size/l labels Jul 14, 2026
@goutamadwant

Copy link
Copy Markdown
Contributor Author

Thanks @NathanTempest. I pushed a follow-up to address your comments. let me know if you have more suggestions. thanks!

@github-actions

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TOML parse error shows incorrect location

2 participants