## cli.exit_code()


The exit code for one of this package's exceptions, or `None` for any other.


Usage

``` python
cli.exit_code(exc)
```


This is part of the host contract with `spice_kernel_db.cli.app` and [logging_to_stderr](cli.logging_to_stderr.md#spice_kernel_db.cli.logging_to_stderr). A program with its own Typer CLI mounts skd's command tree as one of its groups with `app.add_typer(spice_kernel_db.cli.app, name=...)`. This is what planetarypy does as `plp spice`. The host catches what escapes its Typer app and asks here, so both front doors exit the same way. `main()` uses it too (#45, \#49; planetarypy \#51). These three names change only with a major version. The rest of `spice_kernel_db.cli` is internal.

The mapping:

- 1: [MetakernelNotTracked](MetakernelNotTracked.md#spice_kernel_db.MetakernelNotTracked), and [ConcurrentModificationError](ConcurrentModificationError.md#spice_kernel_db.ConcurrentModificationError) (another process changed the kernel records during a download; run the command again).
- 2: [AmbiguousMetakernel](AmbiguousMetakernel.md#spice_kernel_db.AmbiguousMetakernel) and [AmbiguousKernelRoot](AmbiguousKernelRoot.md#spice_kernel_db.AmbiguousKernelRoot), where the candidates are listed and the caller names one, and [MetakernelUnreachableError](MetakernelUnreachableError.md#spice_kernel_db.MetakernelUnreachableError), where the source is gone (HTTP 403, 404 or 410) and the caller decides what to drop.
- 78: [ConfigError](ConfigError.md#spice_kernel_db.ConfigError) and [LegacyDatabaseFound](LegacyDatabaseFound.md#spice_kernel_db.LegacyDatabaseFound), the conventional code for a configuration error. It is never one of [check](check.md#spice_kernel_db.check)'s verdict bits, which use 0 to 7.
- `None`: any exception that is not skd's. A host re-raises it, so a bug keeps its traceback.


## Parameters


`exc: BaseException`  
The exception that escaped the app.


## Returns


`int | None`  
The exit code, or `None` when the exception has no mapping.


## Examples

``` python
>>> import sys
>>> from spice_kernel_db.cli import exit_code, logging_to_stderr
>>> try:
...     with logging_to_stderr():
...         app(standalone_mode=False)  # the host's Typer app
... except Exception as exc:
...     code = exit_code(exc)
...     if code is None:
...         raise
...     print(exc, file=sys.stderr)
...     sys.exit(code)
```
