fix: name the .env path in set_key and unset_key write errors - #711
Conversation
rewrite() creates its temporary file in the target's directory before it touches the target. When that directory is missing or not writable, the OSError named the temporary file instead of the .env path. The error now carries the .env path. `dotenv set` and `dotenv unset` print a short error and exit with code 2 on an OSError, as `get` and `list` do through stream_file. Fixes theskumar#710.
…dd CHANGELOG entry
|
Thanks @jamalkamaladdin, this is the right fix. I reproduced #710 on Why the Windows jobs failed: the code is correct there. The test was the problem: I pushed two commits on top of yours, without changing your commits:
I checked the tests by breaking the code on purpose. Every new test catches at least one of these bugs:
Locally: 264 passed, |
Fixes #710.
src/dotenv/main.py: an OSError from creating a temporary file in
rewrite()now names the .env path.src/dotenv/cli.py:
setandunsetprint "Error writing env file" and exit with code 2 on an OSError.tests/test_main.py: 2 cases for
set_keywith a missing directory and with a read-only directory.tests/test_cli.py: 2 cases for
dotenv setwith a missing directory anddotenv unsetwith a read-only directory.