Skip to content

Malformed .env loads silently #204

Closed

Description

@nickhudkins

I recently had a .env file with the contents:

KEY: Value

and dotenv went about it's business silently not loading anything (I did it wrong).

Is this something we could warn about and say "Hey looks like your file may not be formatted properly?" This seems like it would make for a lovely developer experience.

Activity

  1. theskumar commented on Sep 25, 2019

    @theskumar
    Owner

    I know ansible errors out on such issues. Given how we parse the .env it may not be very straight forward to implement this. But I agree it would be nice to have. @bbc2 what are your thoughts on it?

  2. bbc2 commented on Sep 25, 2019

    @bbc2
    Collaborator

    Good point. I think this has been an issue for some time. In many cases, such as yours, Python-dotenv ignores the problematic lines and attempts to parse the rest.

    For reference, other packages, such as Dotenv in JavaScript or Ruby, seem to behave the same way. However, Bash would exit with an error.

    I can see two ways to move forward:

    1. Logging syntax errors, as you suggested, would be mostly harmless in the worst case, and very useful in general.

    2. We could go further and make the program exit with an appropriate status code, so that the error is really detected (e.g. if running in a test suite). It might break some workflows but I think it would be beneficial. Maybe we could introduce a "strict" mode, or something like that, to test the idea.

    I think (1) would be a good first step. (2) probably requires more thinking.

    I need to look at the code again. It might be reasonably easy to implement thanks to the latest refactoring.

  3. nickhudkins commented on Sep 27, 2019

    @nickhudkins
    Author

    Thanks for the feedback @bbc2 happy to do the work if that is helpful, but if there is a desire for introducing something like strict mode I would want to defer on the architectural choices to you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions