diff options
author | Hasan-Alrimawi <108812045+Hasan-Alrimawi@users.noreply.github.com> | 2024-05-27 16:06:18 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-27 15:06:18 +0200 |
commit | e44c538f37c48f738dea904cffe4cda67f689914 (patch) | |
tree | d6bea2ef03f00fa4be78b89153d249d64f98cc0a /cli/args/mod.rs | |
parent | 8806eac63439a974820ea65dd68aac32b35130fa (diff) |
fix: `--env` flag confusing message on syntax error (#23915)
Enhanced warning message for --env flag with run and eval subcommands.
The commit is specifically made to address issue #23674 by improving the
warning messages that appear when using the --env flag with run or eval
subcommands in the following scenarios:
1. Missing environment file.
2. Incorrect syntax in the environment file content.
**Changes made**
- Distinguishes between cases of missing environment file and wrong
syntax in the environment file content.
- Shows a concise warning message to convey the case/issue occurred.
**Code changes & enhancements**
- Implemented a match statement to handle different types of errors
received while getting and parsing the file content to display a concise
warning message, rather than simple error check and then displaying the
same warning message for whatever the type of error is.
- Updated the related existing tests to reflect the new warning
messages.
- Added two test cases to cover the wrong environment file content
syntax with both run and eval subcommands.
**Impact**
The use of --env flag with both run/eval would be more user-friendly as
it gives a precise description of what is not right when using
incorrectly.
If you could give it a look, @dsherret , I appreciate your feedback on
these changes.
---------
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/args/mod.rs')
-rw-r--r-- | cli/args/mod.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/cli/args/mod.rs b/cli/args/mod.rs index bc384a132..706d98852 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -857,13 +857,17 @@ impl CliOptions { }; if let Some(env_file_name) = &flags.env_file { - if (from_filename(env_file_name)).is_err() { - log::info!( - "{} The `--env` flag was used, but the dotenv file '{}' was not found.", - colors::yellow("Warning"), - env_file_name - ); - } + match from_filename(env_file_name) { + Ok(_) => (), + Err(error) => { + match error { + dotenvy::Error::LineParse(line, index)=> log::info!("{} Parsing failed within the specified environment file: {} at index: {} of the value: {}",colors::yellow("Warning"), env_file_name, index, line), + dotenvy::Error::Io(_)=> log::info!("{} The `--env` flag was used, but the environment file specified '{}' was not found.",colors::yellow("Warning"),env_file_name), + dotenvy::Error::EnvVar(_)=>log::info!("{} One or more of the environment variables isn't present or not unicode within the specified environment file: {}",colors::yellow("Warning"),env_file_name), + _ => log::info!("{} Unknown failure occurred with the specified environment file: {}", colors::yellow("Warning"), env_file_name), + } + } + } } let disable_deprecated_api_warning = flags.log_level |