Open inf17101 opened 10 months ago
I am currently searching the place in the code base where the parsers construct the error messages. Is it possible to just add a new ContextKind
"InvalidEnv" to the enum in case of an inalid env var value and pass this new context kind with the value "environment variable 'SOME_ENV_VAR'" (where SOME_ENV_VAR is the env variable key) to the error?
Then instead of the cli argument name the correct error context is provided.
Could you maybe give a hint, where this code path is?
I am currently searching the place in the code base where the parsers construct the error messages
The value parser. You can update it to use TypedValueParser::parse_
to get the ValueSource
to tell if an env was used.
Is it possible to just add a new ContextKind "InvalidEnv" to the enum in case of an inalid env var value and pass this new context kind with the value "environment variable 'SOME_ENV_VAR'" (where SOME_ENV_VAR is the env variable key) to the error?
Do we need an InvalidEnv
or could we just put the env variable in InvalidArg
?
Ok great thank you for that hint. I will take a look there. I was checking Parser::add_env
also just to see how the arg name is forwarded when env is used.
It is first time I read this code base. I must first get familiar with all the parts 😃
I think we can also use the InvalidArg, but I thought it would be better to not mix cli arg context with env context. But for me it would be also ol to use InvalidArg for the first try.
Please complete the following tasks
Rust Version
rustc 1.72.1 (d5c2e9c34 2023-09-13)
Clap Version
clap: 4.1.4, clap_derive: 4.1.0
Minimal reproducible code
Config.toml
Steps to reproduce the bug with the above code
Actual Behaviour
When running the above command with an invalid value for the environment variable (parser error), then clap does not output the correct context of the wrong value. It outputs that the cli argument was set wrongly, but the user have used an environment variable not the cli argument.
Expected Behaviour
For good use-ability it shall output the correct error message context, for example:
Additional Context
The background is better use-ability. A user might forgot that an environment variable was set manually and tries to execute the program. With the current error message context he gets confused, because he thinks that he did not set this argument.
Debug Output