From b4990d1aa233db662cf22d7f872d45b3a947e0f6 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Mon, 22 Jan 2024 10:27:14 +1100 Subject: [PATCH] refactor: don't error when `.env` is not present (#21879) Uses similar format to when the latest version of std is implicitly being used. Closes #21788 --- cli/args/mod.rs | 6 +++++- cli/tests/integration/eval_tests.rs | 5 +---- cli/tests/integration/run_tests.rs | 5 +---- cli/tests/testdata/eval/env_file_missing.out | 2 ++ cli/tests/testdata/run/env_file_missing.out | 4 ++++ 5 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 cli/tests/testdata/eval/env_file_missing.out create mode 100644 cli/tests/testdata/run/env_file_missing.out diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 2657ed385f..1fdd2f503b 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -725,7 +725,11 @@ impl CliOptions { if let Some(env_file_name) = &flags.env_file { if (from_filename(env_file_name)).is_err() { - bail!("Unable to load '{env_file_name}' environment variable file") + log::info!( + "{} The `--env` flag was used, but the dotenv file '{}' was not found.", + colors::yellow("Warning"), + env_file_name + ); } } diff --git a/cli/tests/integration/eval_tests.rs b/cli/tests/integration/eval_tests.rs index 5d0566a19d..1ae65e49eb 100644 --- a/cli/tests/integration/eval_tests.rs +++ b/cli/tests/integration/eval_tests.rs @@ -85,8 +85,5 @@ itest!(env_file { itest!(env_file_missing { args: "eval --env=missing console.log(Deno.env.get(\"ANOTHER_FOO\"))", - output_str: Some( - "error: Unable to load 'missing' environment variable file\n" - ), - exit_code: 1, + output: "eval/env_file_missing.out", }); diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index 4e3fa8de27..d7d65726ea 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -758,10 +758,7 @@ itest!(env_file { itest!(env_file_missing { args: "run --env=missing --allow-env run/env_file.ts", - output_str: Some( - "error: Unable to load 'missing' environment variable file\n" - ), - exit_code: 1, + output: "run/env_file_missing.out", }); itest!(_091_use_define_for_class_fields { diff --git a/cli/tests/testdata/eval/env_file_missing.out b/cli/tests/testdata/eval/env_file_missing.out new file mode 100644 index 0000000000..221acab934 --- /dev/null +++ b/cli/tests/testdata/eval/env_file_missing.out @@ -0,0 +1,2 @@ +Warning The `--env` flag was used, but the dotenv file 'missing' was not found. +undefined diff --git a/cli/tests/testdata/run/env_file_missing.out b/cli/tests/testdata/run/env_file_missing.out new file mode 100644 index 0000000000..ae1f8f595d --- /dev/null +++ b/cli/tests/testdata/run/env_file_missing.out @@ -0,0 +1,4 @@ +Warning The `--env` flag was used, but the dotenv file 'missing' was not found. +undefined +undefined +undefined