Skip to content

refactor: use custom exception for error handling #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jun 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3983b1b
refactor(error_codes): remove unused NO_COMMIT_MSG error code
Lee-W Jun 5, 2020
8a51843
refactor: use custom exception for error handling
Lee-W Jun 5, 2020
4a1e975
refactor: introduce DryRunExit, ExpectedExit, NoCommandFoundError, In…
Lee-W Jun 5, 2020
68b7d69
refactor(cli): do not show traceback if the raised exception is Commi…
Lee-W Jun 5, 2020
016fba7
test(bump): add test case for --files-only option
Lee-W Jun 14, 2020
168c9f0
style(tests): fix function name typo
Lee-W Jun 14, 2020
ad9d803
test(bump): add test case for dry run
Lee-W Jun 14, 2020
ffb6dde
refactor(exception): implement message handling mechanism for Commiti…
Lee-W Jun 14, 2020
4bfff4d
refactor(exception): move output message related to exception into ex…
Lee-W Jun 14, 2020
799e373
feat(cli): enable displaying all traceback for CommitizenException wh…
Lee-W Jun 14, 2020
da79d1e
test(cz/customize): cover customized info from info_path
Lee-W Jun 14, 2020
182a58f
test(cli): add test cast for commitizen_excepthook
Lee-W Jun 14, 2020
c2893d1
test(commands/commit): add test case for raising non customized excep…
Lee-W Jun 14, 2020
15e7176
test(config): add test case for load global conf
Lee-W Jun 14, 2020
4a1b89b
test: add multiple test cases
Lee-W Jun 14, 2020
3dd29a5
style: reformat
Lee-W Jun 14, 2020
7a8d345
refactor(commands/init): add test case and remove unaccessible code
Lee-W Jun 14, 2020
caf42cc
test(commands/changelog): add test case for running changelog without…
Lee-W Jun 14, 2020
5dfdeeb
test(commands/changelog): add test case when tag name and the latest …
Lee-W Jun 14, 2020
31c570b
refactor(exception): Rename CommitFailedError and TagFailedError with…
Lee-W Jun 14, 2020
a3af3a9
refactor(exception): rename MissingConfigError as MissingCzCustomizeC…
Lee-W Jun 14, 2020
32287f0
docs: exit codes
Lee-W Jun 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(exception): Rename CommitFailedError and TagFailedError with…
… Bump prefix

these errors are only for `cz bump`
  • Loading branch information
Lee-W committed Jun 14, 2020
commit 31c570b4f09e200ab1e2c14634e92b3236e28b9c
8 changes: 4 additions & 4 deletions commitizen/commands/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from commitizen.commands.changelog import Changelog
from commitizen.config import BaseConfig
from commitizen.exceptions import (
CommitFailedError,
BumpCommitFailedError,
BumpTagFailedError,
DryRunExit,
ExpectedExit,
NoCommitsFoundError,
NoPatternMapError,
NoVersionSpecifiedError,
TagFailedError,
)


Expand Down Expand Up @@ -151,10 +151,10 @@ def __call__(self): # noqa: C901
self.config.set_key("version", new_version.public)
c = git.commit(message, args=self._get_commit_args())
if c.err:
raise CommitFailedError(f'git.commit error: "{c.err.strip()}"')
raise BumpCommitFailedError(f'git.commit error: "{c.err.strip()}"')
c = git.tag(new_tag_version)
if c.err:
raise TagFailedError(c.err)
raise BumpTagFailedError(c.err)
out.success("Done!")

def _get_commit_args(self):
Expand Down
12 changes: 6 additions & 6 deletions commitizen/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class ExitCode(enum.IntEnum):
NO_COMMITS_FOUND = 3
NO_VERSION_SPECIFIED = 4
NO_PATTERN_MAP = 5
COMMIT_FAILED = 6
TAG_FAILED = 7
BUMP_COMMIT_FAILED = 6
BUMP_TAG_FAILED = 7
NO_ANSWERS = 8
COMMIT_ERROR = 9
NO_COMMIT_BACKUP = 10
Expand Down Expand Up @@ -84,12 +84,12 @@ class NoPatternMapError(CommitizenException):
exit_code = ExitCode.NO_PATTERN_MAP


class CommitFailedError(CommitizenException):
exit_code = ExitCode.COMMIT_FAILED
class BumpCommitFailedError(CommitizenException):
exit_code = ExitCode.BUMP_COMMIT_FAILED


class TagFailedError(CommitizenException):
exit_code = ExitCode.TAG_FAILED
class BumpTagFailedError(CommitizenException):
exit_code = ExitCode.BUMP_TAG_FAILED


class CurrentVersionNotFoundError(CommitizenException):
Expand Down
4 changes: 2 additions & 2 deletions tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from commitizen import cli, cmd, git
from commitizen.exceptions import (
CommitFailedError,
BumpCommitFailedError,
CurrentVersionNotFoundError,
DryRunExit,
ExpectedExit,
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_bump_on_git_with_hooks_no_verify_disabled(mocker):
testargs = ["cz", "bump", "--yes"]
mocker.patch.object(sys, "argv", testargs)

with pytest.raises(CommitFailedError) as excinfo:
with pytest.raises(BumpCommitFailedError) as excinfo:
cli.main()

assert 'git.commit error: "0.1.0"' in str(excinfo.value)
Expand Down