consolekit.tracebacks

Functions for handling exceptions and their tracebacks.

New in version 1.0.0.

Classes:

TracebackHandler(​)

Context manager to abort execution with a short error message on the following exception types:

Functions:

handle_tracebacks(​[show_traceback, cls])

Context manager to conditionally handle tracebacks, usually based on the value of a command line flag.

traceback_handler(​)

Context manager to abort execution with a short error message on the following exception types:

traceback_option(​[help_text])

Decorator to add the -T / --traceback option to a click command.

class TracebackHandler[source]

Bases: object

Context manager to abort execution with a short error message on the following exception types:

Other custom exception classes inheriting from Exception are also handled, but with a generic message.

The following exception classes are ignored:

How these exceptions are handled can be changed, and supported can be added for further exception classes by subclassing this class. Each method is named in the form handle_<exception>, where exception is the name of the exception class to handle.

New in version 1.0.0.

Methods:

__call__(​)

Use the TracebackHandler with a with block, and handle any exceptions raised within.

handle(​e)

Handle the given exception.

__call__()[source]

Use the TracebackHandler with a with block, and handle any exceptions raised within.

handle(e)[source]

Handle the given exception.

Parameters

e (BaseException)

Return type

bool

handle_tracebacks(show_traceback=False, cls=<class 'TracebackHandler'>)[source]

Context manager to conditionally handle tracebacks, usually based on the value of a command line flag.

New in version 0.8.0.

Parameters

Changed in version 1.0.0: Added the cls parameter.

Return type

AbstractContextManager[+T_co]

traceback_handler()[source]

Context manager to abort execution with a short error message on the following exception types:

Other custom exception classes inheriting from Exception are also handled, but with a generic message.

The following exception classes are ignored:

New in version 0.8.0.

traceback_option(help_text='Show the complete traceback on error.')[source]

Decorator to add the -T / --traceback option to a click command.

The value is exposed via the parameter show_traceback: bool.

New in version 1.0.0.

Parameters

help_text – The help text for the option. Default 'Show the complete traceback on error.'.

Return type

Callable[[~_C], ~_C]