Skip to content
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

--env reports dotenv files as not found when the dotenv file has a syntax error, despite reading from it #23674

Open
KlaasSkelteAtEnatom opened this issue May 3, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@KlaasSkelteAtEnatom
Copy link

Version: Deno 1.43.1

To reproduce:
.env

VALID=valid
INVALID=c:\path

test.ts

console.log(Deno.env.get("VALID"));
console.log(Deno.env.get("INVALID"));

Run with deno -A --env test.ts

Output:

Warning The `--env` flag was used, but the dotenv file '.env' was not found.
valid
undefined

This is an improvement over older versions, because it at least loads something. Still, I'd rather have deno not show the warning, because it is factually wrong.

@dsherret dsherret added the bug Something isn't working label May 3, 2024
@Hasan-Alrimawi
Copy link
Contributor

Hello,
@dsherret
I’m interested in tackling this issue.
I'd like to give it a shot.

@dsherret
Copy link
Member

@Hasan-Alrimawi sure!

marvinhagemeister pushed a commit that referenced this issue May 27, 2024
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants