Repository navigation
fix(changelog): report an unwritable changelog file - #2125
Open
qianeric-backup wants to merge 1 commit into
Open
qianeric-backup wants to merge 1 commit into
qianeric-backup wants to merge 1 commit into
Conversation
`cz changelog --file path/to/CHANGELOG.md` crashed with a traceback when the
file could not be written, for example when the parent directory does not exist:
$ cz changelog --file /nope/CHANGELOG.md
Traceback (most recent call last):
File "commitizen/commands/changelog.py", line 166, in _write_changelog
with smart_open(
File "commitizen/git.py", line 206, in smart_open
return open(name, mode, encoding=encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/nope/CHANGELOG.md'
Every other command reports such a problem with a dedicated exception and exit
code. This change adds `UnableToWriteChangelog` with the new
`ExitCode.CHANGELOG_WRITE_FAILED` (33) and raises it from `_write_changelog`:
$ cz changelog --file /nope/CHANGELOG.md
Unable to write the changelog file '/nope/CHANGELOG.md': [Errno 2] No such
file or directory: '/nope/CHANGELOG.md'
$ echo $?
33
Unchanged: a writable `--file` path writes the changelog, `--dry-run` does not
touch the filesystem, and the in-place `CHANGELOG.md` flow keeps working.
Tests: `test_changelog_unwritable_file` in `tests/commands/test_changelog_command.py`
covers the case (fails with the traceback before the change).
Assisted By: AI
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cz changelog --file path/to/CHANGELOG.mdcrashed with a traceback when the file could not be written, for example when the parent directory does not exist:Every other command reports such a problem with a dedicated exception and exit code.
Change
Adds
UnableToWriteChangelogwith the newExitCode.CHANGELOG_WRITE_FAILED(33), raised from_write_changelog:--filein a missing directoryUnable to write the changelog file ..., exit 33--filein a writable directory--filedefault (CHANGELOG.md)--dry-runThe
OSErroris caught only around thesmart_opencall, so an error raised by achangelog_hookkeeps its own behaviour.Tests
New
test_changelog_unwritable_fileintests/commands/test_changelog_command.py; it fails with the rawFileNotFoundErrorbefore the change and passes after. I could not run the whole suite here — the container has nopython3-venv, so the project'spytestplugins (freezer, regressions) are only partially available; the new test and its neighbours were run directly.Note
cz changelog --file some/dir/CHANGELOG.mddoes not create the parent directory, which is the reason this case came up. Creating it like--result-jsondoes in other tools is a separate decision; this PR only makes the failure visible.Assisted By: AI