Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 34ba400

Browse files
KyleKingLee-W
authored andcommitted
refactor: raise an InvalidConfigurationError
1 parent 9d1a53e commit 34ba400

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

‎commitizen/changelog.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from jinja2 import Environment, PackageLoader
3535

3636
from commitizen import defaults
37+
from commitizen.exceptions import InvalidConfigurationError
3738
from commitizen.git import GitCommit, GitTag
3839

3940
CATEGORIES = [
@@ -131,7 +132,7 @@ def generate_tree_from_commits(
131132

132133
def order_changelog_tree(tree: Iterable, change_type_order: List[str]) -> Iterable:
133134
if len(set(change_type_order)) != len(change_type_order):
134-
raise RuntimeError(
135+
raise InvalidConfigurationError(
135136
f"Change types contain duplicates types ({change_type_order})"
136137
)
137138

‎commitizen/exceptions.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class ExitCode(enum.IntEnum):
2323
NO_REVISION = 16
2424
CURRENT_VERSION_NOT_FOUND = 17
2525
INVALID_COMMAND_ARGUMENT = 18
26+
INVALID_CONFIGURATION = 19
2627

2728

2829
class CommitizenException(Exception):
@@ -137,3 +138,7 @@ class NoCommandFoundError(CommitizenException):
137138

138139
class InvalidCommandArgumentError(CommitizenException):
139140
exit_code = ExitCode.INVALID_COMMAND_ARGUMENT
141+
142+
143+
class InvalidConfigurationError(CommitizenException):
144+
exit_code = ExitCode.INVALID_CONFIGURATION

‎docs/exit_codes.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ These exit codes can be found in `commitizen/exceptions.py::ExitCode`.
2626
| NoRevisionError | 16 | No revision found |
2727
| CurrentVersionNotFoundError | 17 | current version cannot be found in *version_files* |
2828
| InvalidCommandArgumentError | 18 | The argument provide to command is invalid (e.g. `cz check -commit-msg-file filename --rev-range master..`) |
29+
| InvalidConfigurationError | 19 | An error was found in the Commitizen Configuration, such as duplicates in `change_type_order` |

‎tests/test_changelog.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22

33
from commitizen import changelog, defaults, git
4+
from commitizen.exceptions import InvalidConfigurationError
45

56
COMMITS_DATA = [
67
{
@@ -833,10 +834,10 @@ def test_order_changelog_tree(change_type_order, expected_reordering):
833834

834835
def test_order_changelog_tree_raises():
835836
change_type_order = ["BREAKING CHANGE", "feat", "refactor", "feat"]
836-
with pytest.raises(RuntimeError) as excinfo:
837+
with pytest.raises(InvalidConfigurationError) as excinfo:
837838
changelog.order_changelog_tree(COMMITS_TREE, change_type_order)
838839

839-
assert " duplicate" in str(excinfo)
840+
assert "Change types contain duplicates types" in str(excinfo)
840841

841842

842843
def test_render_changelog(gitcommits, tags, changelog_content):

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /