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 /tests | |
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 'tests')
-rw-r--r-- | tests/specs/eval/env_unparsable_file/__test__.jsonc | 4 | ||||
-rw-r--r-- | tests/specs/eval/env_unparsable_file/main.out | 2 | ||||
-rw-r--r-- | tests/specs/run/env_unparsable_file/__test__.jsonc | 4 | ||||
-rw-r--r-- | tests/specs/run/env_unparsable_file/main.js | 3 | ||||
-rw-r--r-- | tests/specs/run/env_unparsable_file/main.out | 4 | ||||
-rw-r--r-- | tests/testdata/env_unparsable | 4 | ||||
-rw-r--r-- | tests/testdata/eval/env_file_missing.out | 2 | ||||
-rw-r--r-- | tests/testdata/run/env_file_missing.out | 2 |
8 files changed, 23 insertions, 2 deletions
diff --git a/tests/specs/eval/env_unparsable_file/__test__.jsonc b/tests/specs/eval/env_unparsable_file/__test__.jsonc new file mode 100644 index 000000000..cf5e9a99b --- /dev/null +++ b/tests/specs/eval/env_unparsable_file/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "eval --env=../../../testdata/env_unparsable console.log(Deno.env.get(\"Another_FOO\"))", + "output": "main.out" +} diff --git a/tests/specs/eval/env_unparsable_file/main.out b/tests/specs/eval/env_unparsable_file/main.out new file mode 100644 index 000000000..18d7856b4 --- /dev/null +++ b/tests/specs/eval/env_unparsable_file/main.out @@ -0,0 +1,2 @@ +Warning Parsing failed within the specified environment file: ../../../testdata/env_unparsable at index: 3 of the value: c:\path +undefined diff --git a/tests/specs/run/env_unparsable_file/__test__.jsonc b/tests/specs/run/env_unparsable_file/__test__.jsonc new file mode 100644 index 000000000..bed150635 --- /dev/null +++ b/tests/specs/run/env_unparsable_file/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "run --env=../../../testdata/env_unparsable --allow-env main.js", + "output": "main.out" +} diff --git a/tests/specs/run/env_unparsable_file/main.js b/tests/specs/run/env_unparsable_file/main.js new file mode 100644 index 000000000..48488ce72 --- /dev/null +++ b/tests/specs/run/env_unparsable_file/main.js @@ -0,0 +1,3 @@ +console.log(Deno.env.get("FOO")); +console.log(Deno.env.get("ANOTHER_FOO")); +console.log(Deno.env.get("MULTILINE")); diff --git a/tests/specs/run/env_unparsable_file/main.out b/tests/specs/run/env_unparsable_file/main.out new file mode 100644 index 000000000..a19ff4dd6 --- /dev/null +++ b/tests/specs/run/env_unparsable_file/main.out @@ -0,0 +1,4 @@ +Warning Parsing failed within the specified environment file: ../../../testdata/env_unparsable at index: 3 of the value: c:\path +valid +undefined +undefined diff --git a/tests/testdata/env_unparsable b/tests/testdata/env_unparsable new file mode 100644 index 000000000..5542b80bc --- /dev/null +++ b/tests/testdata/env_unparsable @@ -0,0 +1,4 @@ +FOO=valid +ANOTHER_FOO=c:\path +MULTILINE="First Line +Second Line"
\ No newline at end of file diff --git a/tests/testdata/eval/env_file_missing.out b/tests/testdata/eval/env_file_missing.out index 221acab93..2ec371438 100644 --- a/tests/testdata/eval/env_file_missing.out +++ b/tests/testdata/eval/env_file_missing.out @@ -1,2 +1,2 @@ -Warning The `--env` flag was used, but the dotenv file 'missing' was not found. +Warning The `--env` flag was used, but the environment file specified 'missing' was not found. undefined diff --git a/tests/testdata/run/env_file_missing.out b/tests/testdata/run/env_file_missing.out index ae1f8f595..6ec9b298f 100644 --- a/tests/testdata/run/env_file_missing.out +++ b/tests/testdata/run/env_file_missing.out @@ -1,4 +1,4 @@ -Warning The `--env` flag was used, but the dotenv file 'missing' was not found. +Warning The `--env` flag was used, but the environment file specified 'missing' was not found. undefined undefined undefined |