"Invalid X errors" should indicate what the valid format is
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 40.5k
- Forks
- 2.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 85
Description
Related problem
Recently I was trying to implement a custom command and wondered what the right syntax for a multi-word parameter was. Since I was following the documentation about custom commands, I guessed that I should use a dash since "it's common practice in Nushell to separate the words of the command with - for better readability". So I tried the following:
export def foo [bar-bar: string] {
print $bar-bar
}
but this resulted in:
Error: nu::parser::parse_mismatch
× Parse mismatch during operation.
╭─[test.nu:1:1]
1 │ export def foo [bar-bar: string] {
· ────┬───
· ╰── expected valid variable name for this parameter
2 │ print $bar-bar
╰────
I was then stuck for a bit, because I couldn't find anything in the docs about what a valid variable name was. I figured it out by matching the parse error to the Nushell source code, but that's not a great user experience :(
Describe the solution you'd like
The diagnostic should include further information about what a valid variable name is. This potentially applies to other "invalid X" errors (I haven't checked if other diagnostics have the same problem).
Describe alternatives you've considered
No response
Additional context and details
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in crates/nu-parser/src/parse_patterns.rs at the linked handling for invalid variable names, using the custom-command example in the issue to reproduce the diagnostic. Update the error guidance so it explains the valid parameter-name format, then verify that the example reports the additional information.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100