Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error reporting for boolean attribute syntax errors #110

Open
andrewmd5 opened this issue Dec 30, 2024 · 1 comment
Open

Improve error reporting for boolean attribute syntax errors #110

andrewmd5 opened this issue Dec 30, 2024 · 1 comment
Labels
needs more info More information is needed before work can continue

Comments

@andrewmd5
Copy link

Description
When encountering boolean attributes with incorrect syntax (missing # prefix), the parser currently backtracks and produces a confusing error message about plain identifiers in an unrelated location. This makes debugging more difficult, especially since the VSCode syntax highlighting can make the incorrect syntax appear valid.

Current Behavior
Given this snippet:

env {
  var1 value1
  var2 value2
}
file "My File" type=file required=true {
  description "File to be transformed"
  value $workflow.file
}

The parser produces this error:

Error:
  × Expected a valid node entry.
    ╭─[11:8]
 10 │ env {
 11 │   var1 value1
    ·        ───┬──
    ·           ╰── plain identifiers can't be used here
 12 │   var2 value2

The error points to value1 in the env block, rather than the actual issue: required=true should be required=#true.

Expected Behavior
The parser should detect and report the missing # prefix for boolean attributes directly. For example:

Error:
  × Invalid boolean attribute syntax
    ╭─[line:col]
    │ file "My File" type=file required=true {
    ·                            ───┬──────
    ·                               ╰── boolean values must be prefixed with '#'
    ╰────
  help: Use 'required=#true' instead of 'required=true'

Additional Context

  • The VSCode extension's syntax highlighting treats boolean keywords specially, which can mask this syntax error visually
  • This type of error can be particularly confusing for new users who are familiar with other config formats where boolean values don't require special prefixes
  • Improving the error message would help users identify and fix the issue more quickly

Possible Solution
Add specific error detection for boolean attributes without the # prefix, rather than falling back to generic parsing rules that result in unrelated error messages.

Let me know if you would like any additional information or clarification!

@zkat
Copy link
Member

zkat commented Jan 1, 2025

I finally got some time to look at this and: this isn't the v2 parser doing this. It's the v1 parser.

How are you parsing this file? Only KDL >6.0.0 is able to parse v2. The first error you showed is indeed, correct, when a file is being parsed in v1 mode.

@zkat zkat added the needs more info More information is needed before work can continue label Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info More information is needed before work can continue
Projects
None yet
Development

No branches or pull requests

2 participants