| 1 |
# Exit Codes |
| 2 |
|
| 3 |
Commitizen handles expected exceptions through `CommitizenException` and returns different exit codes for different situations. This reference is useful when you need to ignore specific errors in your CI/CD pipeline or automation scripts. |
| 4 |
|
| 5 |
All exit codes are defined in [commitizen/exceptions.py](https://github.com/commitizen-tools/commitizen/blob/master/commitizen/exceptions.py). |
| 6 |
|
| 7 |
## Exit Code Reference |
| 8 |
|
| 9 |
| Exception | Exit Code | Description | |
| 10 |
| --------------------------- | --------- | ----------------------------------------------------------------------------------------------------------- | |
| 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 | Invalid combination of command line / configuration file options | |
| 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 is not found | |
| 43 |
| `ConfigFileIsEmpty` | 31 | The configuration file is empty | |
| 44 |
| `CommitMessageLengthLimitExceededError`| 32 | The commit message length exceeds the given limit. | |
| 45 |
|
| 46 |
## Ignoring Exit Codes |
| 47 |
|
| 48 |
In some scenarios, you may want Commitizen to continue execution even when certain errors occur. This is particularly useful in CI/CD pipelines where you want to handle specific errors gracefully. |
| 49 |
|
| 50 |
### Using `--no-raise` Flag |
| 51 |
|
| 52 |
The `--no-raise` (or `-nr`) flag allows you to specify exit codes that should not cause Commitizen to exit with an error. You can use either: |
| 53 |
|
| 54 |
- **Exit code numbers**: `21`, `3`, `4` |
| 55 |
- **Exit code names**: `NO_INCREMENT`, `NO_COMMITS_FOUND`, `NO_VERSION_SPECIFIED` |
| 56 |
- **Mixed format**: `21,NO_COMMITS_FOUND,4` |
| 57 |
|
| 58 |
Multiple exit codes can be specified as a comma-separated list. |
| 59 |
|
| 60 |
!!! warning "Flag placement" |
| 61 |
`--no-raise` / `-nr` is a **top-level Commitizen flag**, so it must be passed |
| 62 |
**before** the subcommand: |
| 63 |
|
| 64 |
```sh |
| 65 |
cz --no-raise 21 bump --yes # ✅ correct |
| 66 |
cz -nr 21 bump --yes # ✅ correct (short form) |
| 67 |
``` |
| 68 |
|
| 69 |
Placing it after the subcommand fails with exit code 18 |
| 70 |
(`InvalidCommandArgumentError`): |
| 71 |
|
| 72 |
```sh |
| 73 |
cz bump --yes --no-raise 21 # ❌ wrong |
| 74 |
# Invalid commitizen arguments were found: `--no-raise`. |
| 75 |
# Please use -- separator for extra git args |
| 76 |
``` |
| 77 |
|
| 78 |
### Common Use Cases |
| 79 |
|
| 80 |
#### Ignoring No Increment Errors |
| 81 |
|
| 82 |
The most common use case is to ignore `NoneIncrementExit` (exit code 21) when running `cz bump`. This allows the command to succeed even when no commits are eligible for a version bump: |
| 83 |
|
| 84 |
```sh |
| 85 |
cz -nr 21 bump |
| 86 |
``` |
| 87 |
|
| 88 |
Or using the exit code name: |
| 89 |
|
| 90 |
```sh |
| 91 |
cz -nr NO_INCREMENT bump |
| 92 |
``` |
| 93 |
|
| 94 |
This is useful in CI pipelines where you want to run `cz bump` regularly, but don't want the pipeline to fail when there are no version-worthy commits. |
| 95 |
|
| 96 |
#### Ignoring Multiple Exit Codes |
| 97 |
|
| 98 |
You can ignore multiple exit codes at once: |
| 99 |
|
| 100 |
```sh |
| 101 |
cz --no-raise 21,3,4 bump |
| 102 |
``` |
| 103 |
|
| 104 |
This example ignores: |
| 105 |
|
| 106 |
- `21` (`NoneIncrementExit`) - No eligible commits for bump |
| 107 |
- `3` (`NoCommitsFoundError`) - No commits found |
| 108 |
- `4` (`NoVersionSpecifiedError`) - Version not specified |
| 109 |
|
| 110 |
### Finding the Exit Code |
| 111 |
|
| 112 |
If you encounter an error and want to ignore it, you can find the exit code in two ways: |
| 113 |
|
| 114 |
#### Method 1: Check the Exit Code After Running |
| 115 |
|
| 116 |
After running a Commitizen command that fails, check the exit code: |
| 117 |
|
| 118 |
```sh |
| 119 |
cz bump |
| 120 |
echo $? # Prints the exit code (e.g., 21) |
| 121 |
``` |
| 122 |
|
| 123 |
Then use that exit code with `--no-raise`: |
| 124 |
|
| 125 |
```sh |
| 126 |
cz -nr 21 bump |
| 127 |
``` |
| 128 |
|
| 129 |
#### Method 2: Look Up the Exception |
| 130 |
|
| 131 |
1. Check the error message to identify the exception type |
| 132 |
2. Find the corresponding exit code in the table above |
| 133 |
3. Use that exit code with `--no-raise` |
| 134 |
|
| 135 |
For example, if you see `NoneIncrementExit` in the error, look it up in the table to find it's exit code 21, then use: |
| 136 |
|
| 137 |
```sh |
| 138 |
cz -nr 21 bump |
| 139 |
``` |
| 140 |
|
| 141 |
### Best Practices |
| 142 |
|
| 143 |
- **Document your usage**: If you use `--no-raise` in scripts or CI/CD, document why specific exit codes are ignored |
| 144 |
- **Be specific**: Only ignore exit codes you understand and have a reason to ignore |
| 145 |
- **Test thoroughly**: Ensure that ignoring certain exit codes doesn't mask real problems in your workflow |
| 146 |
- **Use exit code names**: When possible, use exit code names (e.g., `NO_INCREMENT`) instead of numbers for better readability |
| 147 |
|
| 148 |
### Example: CI/CD Pipeline |
| 149 |
|
| 150 |
Here's an example of using `--no-raise` in a CI/CD pipeline: |
| 151 |
|
| 152 |
```yaml |
| 153 |
# .github/workflows/release.yml |
| 154 |
- name: Bump version |
| 155 |
run: | |
| 156 |
cz -nr NO_INCREMENT bump || true |
| 157 |
# Continue even if no version bump is needed |
| 158 |
``` |
| 159 |
|
| 160 |
This ensures the pipeline continues even when there are no commits eligible for a version bump. |