-
Notifications
You must be signed in to change notification settings - Fork 427
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
dotenv_load with bad file path doesn't error #164
Comments
Thank you for reporting this issue. I observe the same behavior as you. I had a look at the code and it's pretty obvious that What Your suggestion - raising an exception if the file wasn't found - is a good idea in general. However, it's normal for a .env file to be absent (e.g. in staging or in production), so I would say the boolean approach makes more sense here. |
A boolean return value to indicate success or failure would be helpful. It looks like that's hardcoded to |
It actually does throw an exception if you set |
The return value of load_dotenv is undocumented as I was planning to do something useful with it, but could not settle down to one. I think it make sense to return proper return based on if file was found or not, but if the idea is to just stop execution if no .env is found I think it would make much more sense to just pass it a It would be great to return a getter object/function as return value of e.g.
It may also contain some of the meta info like file_path.
|
I can make a PR for this! From the above discussion, my understanding is we want to have an option to fail silently or with an exception. If it fails silently, we want to reflect the status and other metadata in the return value. Do we want to do this irrespective of the value of |
My preference would be stop execution if the env file is not found, but to also be able to silently fail if desired. In general, silent failures aren't a great idea, but I think it should be an option considering the use cases for dotenv. Regardless, knowing what happened is the key whether or not verbose is set to true, which shouldn't be a requirement to know if something failed in my opinion. |
I agree, my opinion is also that it should be independent of the |
Thanks to #211, errors are not silent anymore. Does that work for you? However, there's still no way to stop execution when syntax errors are found in the Returning whether a |
Never mind my initial question about syntax warnings. It's different from the "file not found" question. I mixed up those two types of errors. |
+1 for that issue. |
Sad :( Having used many other Python libraries, I personally find this behavior to be unexpected and confusing. |
Dotenv accepts a bad file name as
dotenv_path
and returnsTrue
even though the file could not have been loaded because it doesn't exist. I am now checking for existence of the file ahead of time, but the library really should check this on its own. Libraries that interact with files should throw exceptions when the files are inaccessible.The text was updated successfully, but these errors were encountered: