René's URL Explorer Experiment


Title: fix(changelog): clearer error when changelog format cannot be inferred by bearomorphism · Pull Request #1973 · commitizen-tools/commitizen · GitHub

Open Graph Title: fix(changelog): clearer error when changelog format cannot be inferred by bearomorphism · Pull Request #1973 · commitizen-tools/commitizen

X Title: fix(changelog): clearer error when changelog format cannot be inferred by bearomorphism · Pull Request #1973 · commitizen-tools/commitizen

Description: Description Closes #894. Why Since commitizen 3.12, running cz changelog with a non-standard --file-name such as docs/source/changelog.md.sections (a Sphinx-style sectioned changelog file) fails with the message Unknown changelog format 'None'. The error is cryptic: it exposes an internal None Python value rather than explaining what went wrong or what the user should do. The failure path is get_changelog_format (commitizen/changelog_formats/__init__.py:64–80). When changelog_format is not set in the config, name is None. The function then calls _guess_changelog_format(filename) (__init__.py:83–98), which matches the filename against known extensions. A filename like changelog.md.sections does not end with .md — endswith requires the final suffix — so inference returns None. At line 78, the single raise path always formats the message as f"Unknown changelog format '{name}'", which prints Unknown changelog format 'None' regardless of whether the problem was a bad explicit setting or a failed inference. The original reporter (@gsemet) filed the issue in October 2023; a second user (@anthonyfinch) hit the same problem shortly after, and triage in #1964 confirmed the bug is still present against master (v4.15.1). The fix splits the error into two distinct, actionable messages — one for each failure mode — and both messages list the registered format names so users know exactly what to write in changelog_format. What changed File Change commitizen/changelog_formats/__init__.py Split the single raise ChangelogFormatUnknown in get_changelog_format (line 78) into two branches: one for an explicitly-set-but-unknown name, one for inference failure; both append Known formats: tests/test_changelog_formats.py Strengthened test_get_format_empty_filename_no_setting and test_get_format_unknown to assert the new message content; added test_get_format_unknown_name_lists_known_formats for the explicit-bad-name path How it works KNOWN_CHANGELOG_FORMATS (commitizen/changelog_formats/__init__.py:58–61) is a dict populated from commitizen.changelog_format entry-points at module import time. Third-party plugins that register their own format are automatically included in the list — the message is always accurate. The new logic builds known = ", ".join(sorted(KNOWN_CHANGELOG_FORMATS)) once, then branches: If name is truthy (the user explicitly set changelog_format to an unrecognised value): "Unknown changelog format '{name}'. Known formats: {known}." — echoes the bad value so it's easy to spot a typo. Otherwise (inference failed): "Cannot infer changelog format from filename '{filename}'. Set the \changelog_format` setting explicitly. Known formats: {known}."` — names the offending filename and points directly to the fix. Why not silently default to Markdown? A silent fallback would mask real misconfiguration: a user who runs a Sphinx .rst workflow and forgets to set changelog_format = "restructuredtext" would get a Markdown-parsed changelog written into their .rst file, corrupting it without any warning. An explicit error that explains what to do is safer. Why list sorted(KNOWN_CHANGELOG_FORMATS) rather than a hard-coded string? The list is derived from entry-points, so it includes third-party plugins and stays accurate if a format is added or removed in future releases. The docstring on get_changelog_format is updated to reference ChangelogFormatUnknown (not the stale FormatUnknown name) and to describe both failure modes. Backward compatibility The exception type raised is unchanged — ChangelogFormatUnknown in both new branches. Success paths are entirely unmodified; users with valid changelog_format settings or standard file extensions see no change. The error message text changes — intentionally — but nothing in the test suite or documented public API depended on the exact string "Unknown changelog format 'None'". All 19 existing tests in test_changelog_formats.py pass; the two parametrised tests that previously only checked pytest.raises(ChangelogFormatUnknown) now additionally assert message content. Checklist I have read the contributing guidelines Was generative AI tooling used to co-author this PR? Yes (please specify the tool below) Generated-by: Claude following the guidelines Code Changes Add test cases to all the changes you introduce Run uv run poe all locally to ensure this change passes linter check and tests Manually test the changes (see "Steps to Test" below) Update the documentation for the changes Expected Behavior Scenario Outcome cz changelog --file-name CHANGELOG.weird (no changelog_format set) Error: Cannot infer changelog format from filename 'CHANGELOG.weird'. Set the \changelog_format` setting explicitly. Known formats: asciidoc, markdown, restructuredtext, textile.` changelog_format = "definitely-not-a-format" in config Error: Unknown changelog format 'definitely-not-a-format'. Known formats: asciidoc, markdown, restructuredtext, textile. cz changelog --file-name docs/source/changelog.md.sections (exact reproducer from #894) Same inference-failure message naming changelog.md.sections changelog_format = "markdown" with any filename Success — no change to happy path Steps to Test This Pull Request git fetch fork fix/894-better-changelog-format-error git checkout fork/fix/894-better-changelog-format-error # 1. Targeted regression test. uv run pytest tests/test_changelog_formats.py::test_get_format_unknown_name_lists_known_formats \ tests/test_changelog_formats.py::test_get_format_unknown \ tests/test_changelog_formats.py::test_get_format_empty_filename_no_setting -v # 2. Reproduce the bug (exact command from the issue), then verify the fix. mkdir /tmp/cz894 && cd /tmp/cz894 git init -b main git config user.name test && git config user.email test@test.com cat > cz.toml << 'EOF' [tool.commitizen] name = "cz_conventional_commits" version = "0.1.0" EOF git add cz.toml git commit -m "fix: initial commit" cz bump --yes # Before the fix: prints "Unknown changelog format 'None'" (exit 29). # After the fix: prints a message naming changelog.md.sections and listing known formats. cz changelog \ --file-name docs/source/changelog.md.sections \ --unreleased-version UNRELEASED_VERSION \ --dry-run 2>&1 || true # Also exercise the explicit-bad-name path: CZ_CHANGELOG_FORMAT=definitely-not-a-format \ cz changelog --dry-run 2>&1 || true # Should print "Unknown changelog format 'definitely-not-a-format'. Known formats: ..." Additional Context This is one of three bugs surfaced by the triage audit in #1964. The fix is intentionally minimal — error messages only, zero behaviour change on success paths. A follow-up could consider defaulting to markdown when inference fails (as suggested in the triage comment), but that is a separate decision with broader implications and belongs in its own PR.

Open Graph Description: Description Closes #894. Why Since commitizen 3.12, running cz changelog with a non-standard --file-name such as docs/source/changelog.md.sections (a Sphinx-style sectioned changelog file) fails wi...

X Description: Description Closes #894. Why Since commitizen 3.12, running cz changelog with a non-standard --file-name such as docs/source/changelog.md.sections (a Sphinx-style sectioned changelog file) fails wi...

Opengraph URL: https://github.com/commitizen-tools/commitizen/pull/1973

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:bf73d73e-5c63-64d3-15f7-22ba303a7ff0
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idCA3C:2095E1:2827885:37AAA6A:6A4F566E
html-safe-nonce8c105d9f92edcfa0725b0a34317e23f7e94ff963de02cc05c0214a4424b2907f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQTNDOjIwOTVFMToyODI3ODg1OjM3QUFBNkE6NkE0RjU2NkUiLCJ2aXNpdG9yX2lkIjoiNzAyMzA0MTk0MDUwMjMwNDM2NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacf0d7aa6aa67dd1941925ccbbf81a972f83f3a21ea253601fb35d39d7767466c6
hovercard-subject-tagpull_request:3654729169
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/commitizen-tools/commitizen/pull/1973/files
twitter:imagehttps://avatars.githubusercontent.com/u/26526132?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/26526132?s=400&v=4
og:image:altDescription Closes #894. Why Since commitizen 3.12, running cz changelog with a non-standard --file-name such as docs/source/changelog.md.sections (a Sphinx-style sectioned changelog file) fails wi...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneb92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/commitizen-tools/commitizen git https://github.com/commitizen-tools/commitizen.git
octolytics-dimension-user_id62252524
octolytics-dimension-user_logincommitizen-tools
octolytics-dimension-repository_id106127589
octolytics-dimension-repository_nwocommitizen-tools/commitizen
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id106127589
octolytics-dimension-repository_network_root_nwocommitizen-tools/commitizen
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseb14b8c6d72fdb96ca48aba85dec94fe96ce5adbe
ui-targetcanary-1
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/commitizen-tools/commitizen/pull/1973/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcommitizen-tools%2Fcommitizen%2Fpull%2F1973%2Ffiles
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcommitizen-tools%2Fcommitizen%2Fpull%2F1973%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=commitizen-tools%2Fcommitizen
Reloadhttps://github.com/commitizen-tools/commitizen/pull/1973/files
Reloadhttps://github.com/commitizen-tools/commitizen/pull/1973/files
Reloadhttps://github.com/commitizen-tools/commitizen/pull/1973/files
Please reload this pagehttps://github.com/commitizen-tools/commitizen/pull/1973/files
commitizen-tools https://github.com/commitizen-tools
commitizenhttps://github.com/commitizen-tools/commitizen
Please reload this pagehttps://github.com/commitizen-tools/commitizen/pull/1973/files
Notifications https://github.com/login?return_to=%2Fcommitizen-tools%2Fcommitizen
Fork 344 https://github.com/login?return_to=%2Fcommitizen-tools%2Fcommitizen
Star 3.5k https://github.com/login?return_to=%2Fcommitizen-tools%2Fcommitizen
Code https://github.com/commitizen-tools/commitizen
Issues 116 https://github.com/commitizen-tools/commitizen/issues
Pull requests 45 https://github.com/commitizen-tools/commitizen/pulls
Discussions https://github.com/commitizen-tools/commitizen/discussions
Actions https://github.com/commitizen-tools/commitizen/actions
Projects https://github.com/commitizen-tools/commitizen/projects
Security and quality 0 https://github.com/commitizen-tools/commitizen/security
Insights https://github.com/commitizen-tools/commitizen/pulse
Code https://github.com/commitizen-tools/commitizen
Issues https://github.com/commitizen-tools/commitizen/issues
Pull requests https://github.com/commitizen-tools/commitizen/pulls
Discussions https://github.com/commitizen-tools/commitizen/discussions
Actions https://github.com/commitizen-tools/commitizen/actions
Projects https://github.com/commitizen-tools/commitizen/projects
Security and quality https://github.com/commitizen-tools/commitizen/security
Insights https://github.com/commitizen-tools/commitizen/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fcommitizen-tools%2Fcommitizen%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fcommitizen-tools%2Fcommitizen%2Fissues%2Fnew%2Fchoose
bearomorphismhttps://github.com/bearomorphism
commitizen-tools:masterhttps://github.com/commitizen-tools/commitizen/tree/master
bearomorphism:fix/894-better-changelog-format-errorhttps://github.com/bearomorphism/commitizen/tree/fix/894-better-changelog-format-error
Conversation 6 https://github.com/commitizen-tools/commitizen/pull/1973
Commits 2 https://github.com/commitizen-tools/commitizen/pull/1973/commits
Checks 20 https://github.com/commitizen-tools/commitizen/pull/1973/checks
Files changed https://github.com/commitizen-tools/commitizen/pull/1973/files
Please reload this pagehttps://github.com/commitizen-tools/commitizen/pull/1973/files
fix(changelog): clearer error when changelog format cannot be inferred https://github.com/commitizen-tools/commitizen/pull/1973/files#top
Show all changes 2 commits https://github.com/commitizen-tools/commitizen/pull/1973/files
f10ef61 fix(changelog): clearer error when changelog format cannot be inferred bearomorphism May 9, 2026 https://github.com/commitizen-tools/commitizen/pull/1973/commits/f10ef61b5fbd42376145fff7278caebaebd510c8
931877e fix(changelog_formats): raise on explicit invalid format even with va… bearomorphism May 9, 2026 https://github.com/commitizen-tools/commitizen/pull/1973/commits/931877e66f584ae8d02856f61e12b998df99c7f0
Clear filters https://github.com/commitizen-tools/commitizen/pull/1973/files
Please reload this pagehttps://github.com/commitizen-tools/commitizen/pull/1973/files
Please reload this pagehttps://github.com/commitizen-tools/commitizen/pull/1973/files
__init__.py https://github.com/commitizen-tools/commitizen/pull/1973/files#diff-ed386dd7ab1248bc269c71f280407bb121806ee87ca34684c2de0659d13674c7
test_changelog_formats.py https://github.com/commitizen-tools/commitizen/pull/1973/files#diff-f77c95b2fa599ef4cb01a8767e48a69998eab09231ff934ec4631fae6a793aab
commitizen/changelog_formats/__init__.pyhttps://github.com/commitizen-tools/commitizen/pull/1973/files#diff-ed386dd7ab1248bc269c71f280407bb121806ee87ca34684c2de0659d13674c7
View file https://github.com/commitizen-tools/commitizen/blob/931877e66f584ae8d02856f61e12b998df99c7f0/commitizen/changelog_formats/__init__.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/commitizen-tools/commitizen/pull/1973/{{ revealButtonHref }}
https://github.com/commitizen-tools/commitizen/pull/1973/files#diff-ed386dd7ab1248bc269c71f280407bb121806ee87ca34684c2de0659d13674c7
https://github.com/commitizen-tools/commitizen/pull/1973/files#diff-ed386dd7ab1248bc269c71f280407bb121806ee87ca34684c2de0659d13674c7
tests/test_changelog_formats.pyhttps://github.com/commitizen-tools/commitizen/pull/1973/files#diff-f77c95b2fa599ef4cb01a8767e48a69998eab09231ff934ec4631fae6a793aab
View file https://github.com/commitizen-tools/commitizen/blob/931877e66f584ae8d02856f61e12b998df99c7f0/tests/test_changelog_formats.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/commitizen-tools/commitizen/pull/1973/{{ revealButtonHref }}
https://github.com/commitizen-tools/commitizen/pull/1973/files#diff-f77c95b2fa599ef4cb01a8767e48a69998eab09231ff934ec4631fae6a793aab
Please reload this pagehttps://github.com/commitizen-tools/commitizen/pull/1973/files
Please reload this pagehttps://github.com/commitizen-tools/commitizen/pull/1973/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.