Skip to content

Commit 10e5d7d

Browse files
committed
Fixed bad error checking with SCM
1 parent 6b9ea0b commit 10e5d7d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

bumpversion/scm.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
if TYPE_CHECKING: # pragma: no-coverage
1515
from bumpversion.config import Config
1616

17-
from bumpversion.exceptions import DirtyWorkingDirectoryError, SignedTagsError
17+
from bumpversion.exceptions import BumpVersionError, DirtyWorkingDirectoryError, SignedTagsError
1818

1919
logger = get_indented_logger(__name__)
2020

@@ -54,6 +54,12 @@ class SourceCodeManager:
5454
def commit(cls, message: str, current_version: str, new_version: str, extra_args: Optional[list] = None) -> None:
5555
"""Commit the changes."""
5656
extra_args = extra_args or []
57+
if not current_version:
58+
logger.warning("No current version given, using an empty string.")
59+
current_version = ""
60+
if not new_version:
61+
logger.warning("No new version given, using an empty string.")
62+
new_version = ""
5763

5864
with NamedTemporaryFile("wb", delete=False) as f:
5965
f.write(message.encode("utf-8"))
@@ -66,10 +72,13 @@ def commit(cls, message: str, current_version: str, new_version: str, extra_args
6672
try:
6773
cmd = [*cls._COMMIT_COMMAND, f.name, *extra_args]
6874
subprocess.run(cmd, env=env, capture_output=True, check=True) # noqa: S603
69-
except subprocess.CalledProcessError as exc: # pragma: no-coverage
70-
err_msg = f"Failed to run {exc.cmd}: return code {exc.returncode}, output: {exc.output}"
75+
except (subprocess.CalledProcessError, TypeError) as exc: # pragma: no-coverage
76+
if isinstance(exc, TypeError):
77+
err_msg = f"Failed to run {cls._COMMIT_COMMAND}: {exc}"
78+
else:
79+
err_msg = f"Failed to run {exc.cmd}: return code {exc.returncode}, output: {exc.output}"
7180
logger.exception(err_msg)
72-
raise exc
81+
raise BumpVersionError(err_msg) from exc
7382
finally:
7483
os.unlink(f.name)
7584

0 commit comments

Comments
 (0)