-
Notifications
You must be signed in to change notification settings - Fork 5
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
Intercept Command Line Errors from Clap #429
Comments
Note that we should not follow it exactly but rusts behavior is this: eg: Using
eg: Using
So
Option 2 would allow use to move validation of command line arguments back into |
I think option 2 is the right call, it will give us a bit more flexibility with any validation we want to do just for command line args. So we do the pass with |
After much searching, there is a macro argument you can pass to clap that causes it to ignore errors:
They make it very difficult to find though. We could have 2 structs, one for the 'full parse', and another with only the critical fields in it for 'pre-parsing'. And both times we'd use |
As of #526, the only option that can fail to parse via clap is |
After #619, arguments to |
Clap is the library that we use for generating and displaying a command line interface to the Slice compilers.
Currently, we interact with it with a
parse
method, which attempts to parse a user's command line input.If the user typed everything correctly, it hands us the data pre-parsed in a struct.
If there was an error in the user's input, it displays errors in its own formatting then terminates the program.
I propose we switch to the
try_parse
method, which instead returns aResult<PreParsedData, Errors>
.This way, if an error happens, instead of emitting them and dying, it returns them to
slicec
where we can be in control of how they're emitted.This has the benefit of letting us emit these errors in our own formatting, ensure users, build tools, and our future language server always receive consistently formatted error messages.
It also centralizes where errors can be emitted from; with this change there would only be place (we know of) where errors are stored and emitted: the
DiagnosticReporter
. Instead of having to think about multiple places where failures can be reported from.The text was updated successfully, but these errors were encountered: