Skip to content

Commit 08f521a

Browse files
committed
docs(exit-codes): general update
docs(exception): add comment for updating exit code doc
1 parent f52f532 commit 08f521a

File tree

2 files changed

+108
-36
lines changed

2 files changed

+108
-36
lines changed

commitizen/exceptions.py

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ExitCode(IntEnum):
2929
INVALID_CONFIGURATION = 19
3030
NOT_ALLOWED = 20
3131
NO_INCREMENT = 21
32-
UNRECOGNIZED_CHARACTERSET_ENCODING = 22
32+
CHARACTER_SET_DECODE_ERROR = 22
3333
GIT_COMMAND_ERROR = 23
3434
INVALID_MANUAL_VERSION = 24
3535
INIT_FAILED = 25
@@ -72,32 +72,44 @@ def __init__(self, *args: str, **kwargs: Any) -> None:
7272

7373

7474
class DryRunExit(ExpectedExit):
75-
pass
75+
"""Exit due to passing `--dry-run` option"""
7676

7777

7878
class NoneIncrementExit(CommitizenException):
79+
"""The commits found are not eligible to be bumped"""
80+
7981
exit_code = ExitCode.NO_INCREMENT
8082

8183

8284
class NoCommitizenFoundException(CommitizenException):
85+
"""Using a cz (e.g., `cz_jira`) that cannot be found in your system"""
86+
8387
exit_code = ExitCode.NO_COMMITIZEN_FOUND
8488

8589

8690
class NotAGitProjectError(CommitizenException):
91+
"""Not in a git project"""
92+
8793
exit_code = ExitCode.NOT_A_GIT_PROJECT
8894
message = "fatal: not a git repository (or any of the parent directories): .git"
8995

9096

9197
class MissingCzCustomizeConfigError(CommitizenException):
98+
"""Configuration is missing for `cz_customize`"""
99+
92100
exit_code = ExitCode.MISSING_CZ_CUSTOMIZE_CONFIG
93101
message = "fatal: customize is not set in configuration file."
94102

95103

96104
class NoCommitsFoundError(CommitizenException):
105+
"""No commits found"""
106+
97107
exit_code = ExitCode.NO_COMMITS_FOUND
98108

99109

100110
class NoVersionSpecifiedError(CommitizenException):
111+
"""Version is not specified in configuration file"""
112+
101113
exit_code = ExitCode.NO_VERSION_SPECIFIED
102114
message = (
103115
"[NO_VERSION_SPECIFIED]\n"
@@ -107,111 +119,166 @@ class NoVersionSpecifiedError(CommitizenException):
107119

108120

109121
class NoPatternMapError(CommitizenException):
122+
"""bump / changelog pattern or map can not be found in configuration file"""
123+
110124
exit_code = ExitCode.NO_PATTERN_MAP
111125

112126

113127
class BumpCommitFailedError(CommitizenException):
128+
"""Commit failed when bumping version"""
129+
114130
exit_code = ExitCode.BUMP_COMMIT_FAILED
115131

116132

117133
class BumpTagFailedError(CommitizenException):
134+
"""Tag failed when bumping version"""
135+
118136
exit_code = ExitCode.BUMP_TAG_FAILED
119137

120138

121139
class CurrentVersionNotFoundError(CommitizenException):
140+
"""current version cannot be found in _version_files_"""
141+
122142
exit_code = ExitCode.CURRENT_VERSION_NOT_FOUND
123143

124144

125145
class NoAnswersError(CommitizenException):
146+
"""No user response given"""
147+
126148
exit_code = ExitCode.NO_ANSWERS
127149

128150

129151
class CommitError(CommitizenException):
152+
"""git commit error"""
153+
130154
exit_code = ExitCode.COMMIT_ERROR
131155

132156

133157
class NoCommitBackupError(CommitizenException):
158+
"""Commit backup file is not found"""
159+
134160
exit_code = ExitCode.NO_COMMIT_BACKUP
135161
message = "No commit backup found"
136162

137163

138164
class NothingToCommitError(CommitizenException):
165+
"""Nothing in staging to be committed"""
166+
139167
exit_code = ExitCode.NOTHING_TO_COMMIT
140168

141169

142170
class CustomError(CommitizenException):
171+
"""`CzException` raised"""
172+
143173
exit_code = ExitCode.CUSTOM_ERROR
144174

145175

146176
class InvalidCommitMessageError(CommitizenException):
177+
"""The commit message does not pass `cz check`"""
178+
147179
exit_code = ExitCode.INVALID_COMMIT_MSG
148180

149181

150182
class NoRevisionError(CommitizenException):
183+
"""No revision found"""
184+
151185
exit_code = ExitCode.NO_REVISION
152186
message = "No tag found to do an incremental changelog"
153187

154188

155189
class NoCommandFoundError(CommitizenException):
190+
"""No command found when running Commitizen cli (e.g., `cz --debug`)"""
191+
156192
exit_code = ExitCode.NO_COMMAND_FOUND
157193
message = "Command is required"
158194

159195

160196
class InvalidCommandArgumentError(CommitizenException):
197+
"""The argument provided to the command is invalid (e.g. `cz check -commit-msg-file filename --rev-range master..`)"""
198+
161199
exit_code = ExitCode.INVALID_COMMAND_ARGUMENT
162200

163201

164202
class InvalidConfigurationError(CommitizenException):
203+
"""An error was found in the Commitizen Configuration, such as duplicates in `change_type_order`"""
204+
165205
exit_code = ExitCode.INVALID_CONFIGURATION
166206

167207

168208
class NotAllowed(CommitizenException):
209+
"""`--incremental` cannot be combined with a `rev_range`"""
210+
169211
exit_code = ExitCode.NOT_ALLOWED
170212

171213

172214
class CharacterSetDecodeError(CommitizenException):
173-
exit_code = ExitCode.UNRECOGNIZED_CHARACTERSET_ENCODING
215+
"""The character encoding of the command output could not be determined"""
216+
217+
exit_code = ExitCode.CHARACTER_SET_DECODE_ERROR
174218

175219

176220
class GitCommandError(CommitizenException):
221+
"""Unexpected failure while calling a git command"""
222+
177223
exit_code = ExitCode.GIT_COMMAND_ERROR
178224

179225

180226
class InvalidManualVersion(CommitizenException):
227+
"""Manually provided version is invalid"""
228+
181229
exit_code = ExitCode.INVALID_MANUAL_VERSION
182230

183231

184232
class InitFailedError(CommitizenException):
233+
"""Failed to initialize pre-commit"""
234+
185235
exit_code = ExitCode.INIT_FAILED
186236

187237

188238
class RunHookError(CommitizenException):
239+
"""An error occurred during a hook execution"""
240+
189241
exit_code = ExitCode.RUN_HOOK_FAILED
190242

191243

192244
class VersionProviderUnknown(CommitizenException):
245+
"""Unknown `version_provider`"""
246+
193247
exit_code = ExitCode.VERSION_PROVIDER_UNKNOWN
194248

195249

196250
class VersionSchemeUnknown(CommitizenException):
251+
"""Unknown `version_scheme`"""
252+
197253
exit_code = ExitCode.VERSION_SCHEME_UNKNOWN
198254

199255

200256
class ChangelogFormatUnknown(CommitizenException):
257+
"""Unknown `changelog_format` or cannot be determined by the file extension"""
258+
201259
exit_code = ExitCode.CHANGELOG_FORMAT_UNKNOWN
202260
message = "Unknown changelog format identifier"
203261

204262

205263
class ConfigFileNotFound(CommitizenException):
264+
"""The configuration file could not be found"""
265+
206266
exit_code = ExitCode.CONFIG_FILE_NOT_FOUND
207267
message = "Cannot found the config file, please check your file path again."
208268

209269

210270
class ConfigFileIsEmpty(CommitizenException):
271+
"""The configuration file is empty"""
272+
211273
exit_code = ExitCode.CONFIG_FILE_IS_EMPTY
212274
message = "Config file is empty, please check your file path again."
213275

214276

215277
class CommitMessageLengthExceededError(CommitizenException):
278+
"""The commit message length exceeds the given limit."""
279+
216280
exit_code = ExitCode.COMMIT_MESSAGE_LENGTH_LIMIT_EXCEEDED
217281
message = "Length of commit message exceeds the given limit."
282+
283+
284+
# When adding a new exit code, please update the documentation of the exit codes in docs/exit_codes.md

docs/exit_codes.md

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,44 @@
11
# Exit Codes
22

3-
Commitizen handles expected exceptions through `CommitizenException` and returns different exit codes for different situations. They could be useful if you want to ignore specific errors in your pipeline.
3+
Commitizen handles expected exceptions through `CommitizenException` and returns different exit codes for different situations.
44

5-
These exit codes can be found in `commitizen/exceptions.py::ExitCode`.
5+
The following information may come in handy if you want to ignore specific errors in your pipeline.
6+
7+
These exit codes can be found in [commitizen/exceptions.py](https://github.com/commitizen-tools/commitizen/blob/master/commitizen/exceptions.py).
68

79
| Exception | Exit Code | Description |
810
| --------------------------- | --------- | ----------------------------------------------------------------------------------------------------------- |
9-
| ExpectedExit | 0 | Expected exit |
10-
| DryRunExit | 0 | Exit due to passing `--dry-run` option |
11-
| NoCommitizenFoundException | 1 | Using a cz (e.g., `cz_jira`) that cannot be found in your system |
12-
| NotAGitProjectError | 2 | Not in a git project |
13-
| NoCommitsFoundError | 3 | No commit found |
14-
| NoVersionSpecifiedError | 4 | Version can not be found in configuration file |
15-
| NoPatternMapError | 5 | bump / changelog pattern or map can not be found in configuration file |
16-
| BumpCommitFailedError | 6 | Commit error when bumping version |
17-
| BumpTagFailedError | 7 | Tag error when bumping version |
18-
| NoAnswersError | 8 | No user response given |
19-
| CommitError | 9 | git commit error |
20-
| NoCommitBackupError | 10 | Commit back up file cannot be found |
21-
| NothingToCommitError | 11 | Nothing in staging to be committed |
22-
| CustomError | 12 | `CzException` raised |
23-
| NoCommandFoundError | 13 | No command found when running Commitizen cli (e.g., `cz --debug`) |
24-
| InvalidCommitMessageError | 14 | The commit message does not pass `cz check` |
25-
| MissingConfigError | 15 | Configuration missed for `cz_customize` |
26-
| NoRevisionError | 16 | No revision found |
27-
| CurrentVersionNotFoundError | 17 | current version cannot be found in _version_files_ |
28-
| 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` |
30-
| NotAllowed | 20 | `--incremental` cannot be combined with a `rev_range` |
31-
| NoneIncrementExit | 21 | The commits found are not eligible to be bumped |
32-
| CharacterSetDecodeError | 22 | The character encoding of the command output could not be determined |
33-
| GitCommandError | 23 | Unexpected failure while calling a git command |
34-
| InvalidManualVersion | 24 | Manually provided version is invalid |
35-
| InitFailedError | 25 | Failed to initialize pre-commit |
36-
| RunHookError | 26 | An error occurred during a hook execution |
37-
| VersionProviderUnknown | 27 | `version_provider` setting is set to an unknown version provider identifier |
38-
| VersionSchemeUnknown | 28 | `version_scheme` setting is set to an unknown version scheme identifier |
39-
| ChangelogFormatUnknown | 29 | `changelog_format` setting is set to an unknown version scheme identifier or could not be guessed |
11+
| `ExpectedExit` | 0 | Expected exit |
12+
| `DryRunExit` | 0 | Exit due to passing `--dry-run` option |
13+
| `NoCommitizenFoundException` | 1 | Using a cz (e.g., `cz_jira`) that cannot be found in your system |
14+
| `NotAGitProjectError` | 2 | Not in a git project |
15+
| `NoCommitsFoundError` | 3 | No commits found |
16+
| `NoVersionSpecifiedError` | 4 | Version is not specified in configuration file |
17+
| `NoPatternMapError` | 5 | bump / changelog pattern or map can not be found in configuration file |
18+
| `BumpCommitFailedError` | 6 | Commit failed when bumping version |
19+
| `BumpTagFailedError` | 7 | Tag failed when bumping version |
20+
| `NoAnswersError` | 8 | No user response given |
21+
| `CommitError` | 9 | git commit error |
22+
| `NoCommitBackupError` | 10 | Commit backup file is not found |
23+
| `NothingToCommitError` | 11 | Nothing in staging to be committed |
24+
| `CustomError` | 12 | `CzException` raised |
25+
| `NoCommandFoundError` | 13 | No command found when running Commitizen cli (e.g., `cz --debug`) |
26+
| `InvalidCommitMessageError` | 14 | The commit message does not pass `cz check` |
27+
| `MissingConfigError` | 15 | Configuration is missing for `cz_customize` |
28+
| `NoRevisionError` | 16 | No revision found |
29+
| `CurrentVersionNotFoundError`| 17 | Current version cannot be found in _version_files_ |
30+
| `InvalidCommandArgumentError`| 18 | The argument provided to the command is invalid (e.g. `cz check -commit-msg-file filename --rev-range master..`) |
31+
| `InvalidConfigurationError` | 19 | An error was found in the Commitizen Configuration, such as duplicates in `change_type_order` |
32+
| `NotAllowed` | 20 | `--incremental` cannot be combined with a `rev_range` |
33+
| `NoneIncrementExit` | 21 | The commits found are not eligible to be bumped |
34+
| `CharacterSetDecodeError` | 22 | The character encoding of the command output could not be determined |
35+
| `GitCommandError` | 23 | Unexpected failure while calling a git command |
36+
| `InvalidManualVersion` | 24 | Manually provided version is invalid |
37+
| `InitFailedError` | 25 | Failed to initialize pre-commit |
38+
| `RunHookError` | 26 | An error occurred during a hook execution |
39+
| `VersionProviderUnknown` | 27 | Unknown `version_provider` |
40+
| `VersionSchemeUnknown` | 28 | Unknown `version_scheme` |
41+
| `ChangelogFormatUnknown` | 29 | Unknown `changelog_format` or cannot be determined by the file extension |
42+
| `ConfigFileNotFound` | 30 | The configuration file could not be found |
43+
| `ConfigFileIsEmpty` | 31 | The configuration file is empty |
44+
| `CommitMessageLengthLimitExceededError`| 32 | The commit message length exceeds the given limit. |

0 commit comments

Comments
 (0)