refactor: error handling to use exceptions (#1719)
* Refactor error handling to use exceptions cibuildwheel has up until now handled most errors by printing an error message to sys.stderr and calling sys.exit. Others were handled using Logger.error, depending on the context. We also had return codes, but these weren't explicitly defined anywhere. This makes that convention more explicit and codified. Now to halt the program, the correct thing to do is to throw a cibuildwheel.errors.FatalError exception - that is caught in main() and printed before exiting. The existing behaviour was kept - if an error occurs within a build step (probably something to do with the build itself), the Logger.error() method is used. Outside of a build step (e.g. a misconfiguration), the behaviour is still to print 'cibuildwheel: <message>' I also took the opportunity to add a debugging option `--debug-traceback` (and `CIBW_DEBUG_TRACEBACK`), which you can enable to see a full traceback on errors. (I've deactivated the flake8-errmsg lint rule, as it was throwing loads of errors and these error messages aren't generally seen in a traceback context) * add noqa rule * Apply suggestions from code review Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com> * Return to flake8-errmsg conformance * Code review suggestions * Subclass Exception rather than SystemExit * apply error handling to new code and fix merge issues * Apply review suggestion * fix: merge issue * Update cibuildwheel/errors.py --------- Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com> Co-authored-by: mayeut <mayeut@users.noreply.github.com>
This commit is contained in:
co-authored by
Henry Schreiner
mayeut
parent
384c8d5c82
commit
bf817c6dc8
+28
-1
@@ -1612,6 +1612,20 @@ Default: Off (0).
|
||||
export CIBW_DEBUG_KEEP_CONTAINER=TRUE
|
||||
```
|
||||
|
||||
### `CIBW_DEBUG_TRACEBACK`
|
||||
> Print full traceback when errors occur.
|
||||
|
||||
Print a full traceback for the cibuildwheel process when errors occur. This
|
||||
option is provided for debugging cibuildwheel.
|
||||
|
||||
This option can also be set using the [command-line option](#command-line) `--debug-traceback`.
|
||||
|
||||
#### Examples
|
||||
|
||||
```shell
|
||||
export CIBW_DEBUG_TRACEBACK=TRUE
|
||||
```
|
||||
|
||||
### `CIBW_BUILD_VERBOSITY` {: #build-verbosity}
|
||||
> Increase/decrease the output of pip wheel
|
||||
|
||||
@@ -1638,12 +1652,25 @@ Platform-specific environment variables are also available:<br/>
|
||||
```
|
||||
|
||||
|
||||
## Command line options {: #command-line}
|
||||
## Command line {: #command-line}
|
||||
|
||||
### Options
|
||||
|
||||
```text
|
||||
« subprocess_run("cibuildwheel", "--help") »
|
||||
```
|
||||
|
||||
### Return codes
|
||||
|
||||
cibuildwheel exits 0 on success, or >0 if an error occurs.
|
||||
|
||||
Specific error codes are defined:
|
||||
|
||||
- 2 means a configuration error
|
||||
- 3 means no builds are selected (and --allow-empty wasn't passed)
|
||||
- 4 means you specified an option that has been deprecated.
|
||||
|
||||
|
||||
## Placeholders
|
||||
|
||||
Some options support placeholders, like `{project}`, `{package}` or `{wheel}`, that are substituted by cibuildwheel before they are used. If, for some reason, you need to write the literal name of a placeholder, e.g. literally `{project}` in a command that would ordinarily substitute `{project}`, prefix it with a hash character - `#{project}`. This is only necessary in commands where the specific string between the curly brackets would be substituted - otherwise, strings not modified.
|
||||
|
||||
Reference in New Issue
Block a user