Skip to content

Add contextual hints to parser error messages#18

Merged
dereuromark merged 1 commit into
masterfrom
improve-error-messages
Mar 30, 2026
Merged

Add contextual hints to parser error messages#18
dereuromark merged 1 commit into
masterfrom
improve-error-messages

Conversation

@dereuromark
Copy link
Copy Markdown
Contributor

Summary

Improves parser error messages with helpful hints for common mistakes, especially for users coming from YAML/JSON backgrounds.

The ParseError class already supports hints via the format() method and ParseException has a hint property - this PR adds contextual hints to error messages.

Before / After

Scenario Before After
YAML-style colon version: "1.0" Expected = Expected = + hint: TOML uses `=` for key-value pairs, not `:`. Example: key = "value"
Unquoted string name = hello Expected value Expected value + hint: Strings must be quoted in TOML. Did you mean `"hello"`?
Semver string version = 1.0.0 Invalid token: \1.0.0`` Invalid token: \1.0.0` + hint: *This looks like a version string. Strings must be quoted: \"1.0.0"`*
YAML boolean enabled = yes Expected value Expected value + hint: TOML booleans are `true` or `false`, not `yes`.
Missing ] in [database Expected ] Expected ] + hint: Unclosed bracket. Table headers use [name] syntax.
Missing } in { x = 1 Expected } Expected } + hint: Unclosed brace. Inline tables use { key = value } syntax.
Multiple values a = 1 b = 2 Expected newline or end of input after value Same + hint: Each key-value pair must be on its own line.
Missing key = "value" Unexpected token: \=`` Same + hint: A key is required before `=`. Example: key = "value"
Consecutive dots a..b = 1 Expected key Expected key + hint: Empty key segment. Keys cannot have consecutive dots.

Improve error messages with helpful hints for common mistakes,
especially for users coming from YAML:

- YAML-style colon: "TOML uses = for key-value pairs, not :"
- Unquoted strings: "Strings must be quoted. Did you mean \"hello\"?"
- YAML booleans: "TOML booleans are true or false, not yes/no/on/off"
- Semver strings: "This looks like a version string. Must be quoted"
- Unclosed brackets/braces: Hints about proper syntax
- Multiple values on line: "Each key-value pair must be on its own line"
- Missing key: "A key is required before ="
- Consecutive dots: "Empty key segment. Keys cannot have consecutive dots"

The ParseError class already supports hints via the format() method.
@dereuromark dereuromark merged commit 5633b73 into master Mar 30, 2026
3 checks passed
@dereuromark dereuromark deleted the improve-error-messages branch March 30, 2026 20:23
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.

1 participant