You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Reacted by Anderson Queiroz, Bertrand Bonnefoy-Claudet and Dmitriy Geels
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?
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:
Logging syntax errors, as you suggested, would be mostly harmless in the worst case, and very useful in general.
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.
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!
Activity
theskumar commentedon Sep 25, 2019
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?
bbc2 commentedon Sep 25, 2019
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:
Logging syntax errors, as you suggested, would be mostly harmless in the worst case, and very useful in general.
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.
nickhudkins commentedon Sep 27, 2019
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!