cli.exit_code()
The exit code for one of this package’s exceptions, or None for any other.
Usage
cli.exit_code(exc)This is part of the host contract with spice_kernel_db.cli.app and 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, and ConcurrentModificationError (another process changed the kernel records during a download; run the command again).
- 2: AmbiguousMetakernel and AmbiguousKernelRoot, where the candidates are listed and the caller names one, and MetakernelUnreachableError, where the source is gone (HTTP 403, 404 or 410) and the caller decides what to drop.
- 78: ConfigError and LegacyDatabaseFound, the conventional code for a configuration error. It is never one of 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
Nonewhen the exception has no mapping.
Examples
>>> 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)