Skip to content

Report malformed PKG-INFO as a clean error instead of a traceback - #143

Open
Qrytics wants to merge 1 commit into
jwodder:masterfrom
Qrytics:pilot/slot-541-fix
Open

Qrytics wants to merge 1 commit into
jwodder:masterfrom
Qrytics:pilot/slot-541-fix

Conversation

@Qrytics

@Qrytics Qrytics commented Nov 10, 2026

Copy link
Copy Markdown

Running versioningit in a directory that is not under version
control but contains a PKG-INFO file without a Version field crashes
with an unhandled ValueError traceback:

$ versioningit /path/to/sdist
...
ValueError: Metadata does not contain a Version field

Every other user-facing failure in main() is reported as a clean
one-line versioningit: <ErrorType>: <message> on stderr with a nonzero
exit status. A PKG-INFO file without a Version field is just as much
a user/input problem (e.g. a truncated or hand-written file), so it
should be reported the same way.

This change converts the ValueError from parse_version_from_metadata()
into a NotSdistError inside get_version_from_pkg_info(), so the CLI
now prints:

versioningit: NotSdistError: /path/to/sdist contains an invalid PKG-INFO file: Metadata does not contain a Version field

and exits 1 with no traceback. parse_version_from_metadata() itself is
unchanged (it still raises ValueError, as documented and tested), and
the --traceback flag still shows the full traceback when requested.

Test: added test_command_bad_pkg_info to test/test_main.py, which
builds a project dir with a [tool.versioningit] config plus a
Version-less PKG-INFO, runs main(), and asserts exit status 1,
empty stdout, no Traceback on stderr, and a versioningit: NotSdistError: message. The new test fails before the fix (uncaught
ValueError) and passes after; test_main.py, test_get_version.py,
test_util.py, and test_logging.py all pass (199 passed, 1 skipped).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant