Repository navigation
Fixes
-
Fix(config): report unusable explicit config files without a traceback. 6eebb4f
-
Fix(config): report an unparsable --config-file instead of "Unable to determine the current version". 45c5c29
A malformed
--config-fileis reported as "Unable to determine the current version"Every command accepts
--config-file. When the file exists but is not valid TOML, it is silently ignored and the command runs with the defaults:$ printf '[[[bad\n' > bad.toml $ bump-my-version show --config-file bad.toml ; echo "exit=$?" ╭─ Error ────────────────────────────────────────────────╮ │ Unable to determine the current version. │ ╰────────────────────────────────────────────────────────╯ exit=2bumpandshow-bumpgive the same output. Nothing namesbad.toml, so the only clue is a message about the version.Why
find_config_file()treats an explicit file like a discovery candidate._has_bumpversion_config()parses it through_load_toml_mapping(), which returns{}for invalid TOML. That fallback is intentional for discovery (test_malformed_input_does_not_raise), but for an explicit file it makes the file look absent.read_config_file(None)then only logs a warning andcheck_current_version()fails later with the misleading message.The same option reports the other bad paths cleanly
$ bump-my-version show --config-file /nope.toml │ '/nope.toml' does not exist. │ $ bump-my-version show --config-file /tmp │ '/tmp' is a directory. │A file that exists but cannot be parsed is the third case of the same option, and it is the only one that loses the reason.
Change
find_config_file()returns an explicit file as-is when it exists instead of re-discovering it.read_toml_file()converts tomlkit's parse error intoConfigurationError, which the CLI already renders as a one-line usage error.if explicit_file: - search_paths = [Path(explicit_file)] - else: + explicit_path = Path(explicit_file) + return explicit_path if explicit_path.exists() else None + + cwd = Path.cwd() ... import tomlkit + from tomlkit.exceptions import TOMLKitError + + try: + toml_data = tomlkit.parse(file_path.read_text(encoding="utf-8")).unwrap() + except TOMLKitError as exc: + raise ConfigurationError(f"Unable to parse the configuration file {file_path}: {exc}") from exc
invocation before after show --config-file bad.tomlUnable to determine the current version.Unable to parse the configuration file bad.toml: Empty table name at line 1 col 2show --config-file /nope.toml'/nope.toml' does not exist.unchanged show --config-file /tmp'/tmp' is a directory.unchanged discovery without --config-file, malformed candidatecandidate skipped, defaults unchanged Discovery still skips malformed files: only the explicit path is returned without probing.
Test
Three regression tests in
tests/test_config/test_files.py:def test_returns_a_malformed_file_instead_of_treating_it_as_absent(self, tmp_path: Path) -> None: """A malformed explicit file is returned so reading it can report the parse error.""" cfg_file = tmp_path / "bump.toml" cfg_file.write_text("this is [not toml", encoding="utf-8") assert find_config_file(cfg_file) == cfg_file def test_raises_configuration_error_for_malformed_toml(self, tmp_path: Path) -> None: """A malformed TOML file is reported with its path instead of being treated as absent.""" cfg_file = tmp_path / "bump.toml" cfg_file.write_text("this is [not toml", encoding="utf-8") with pytest.raises(config.ConfigurationError) as excinfo: config.read_config_file(cfg_file) assert str(cfg_file) in str(excinfo.value) def test_reports_a_malformed_file_instead_of_a_missing_version(self, tmp_path: Path, runner) -> None: """The CLI reports the parse error rather than "Unable to determine the current version".""" cfg_file = tmp_path / "bump.toml" cfg_file.write_text("this is [not toml", encoding="utf-8") with inside_dir(tmp_path): result: Result = runner.invoke(cli.cli, ["show", "current_version", "--config-file", str(cfg_file)]) assert result.exit_code == 2 assert "Unable to parse the configuration file" in result.output assert "Unable to determine the current version" not in result.output
Results on Python 3.13:
- unmodified tree with the new tests:
3 failed - patched tree, full suite:
777 passed, 17 skipped ruff check,ruff format --check,interrogate(100%),pydoclint: passmypy bumpversion/: the same 3 pre-existing errors asmaster
- unmodified tree with the new tests: