consolekit.tracebacks
Functions for handling exceptions and their tracebacks.
New in version 1.0.0.
Classes:
|
Context manager to abort execution with a short error message on the following exception types: |
Functions:
|
Context manager to conditionally handle tracebacks, usually based on the value of a command line flag. |
Context manager to abort execution with a short error message on the following exception types: |
|
|
Decorator to add the |
-
class
TracebackHandler
(exception=Abort())[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:
SystemExit
(new in version 1.1.2)
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>
, whereexception
is the name of the exception class to handle.New in version 1.0.0.
- Parameters
exception (
BaseException
) – The exception to raise after handling the traceback. If not running within a click command or group you’ll likely want to set this toSystemExit(1)
. Defaultclick.Abort()
.
Changed in version 1.4.0: Added the
exception
argument.See also
Methods:
__call__
()Use the
TracebackHandler
with awith
block, and handle any exceptions raised within.abort
(msg)Abort the current process by calling
self.exception
.handle
(e)Handle the given exception.
Attributes:
The exception to raise after handling the traceback.
-
__call__
()[source] Use the
TracebackHandler
with awith
block, and handle any exceptions raised within.
-
exception
Type:
Exception
The exception to raise after handling the traceback.
New in version 1.4.0.
-
handle
(e)[source] Handle the given exception.
- Parameters
e (
BaseException
)- Return type
-
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
show_traceback (
bool
) – IfTrue
, the full Python traceback will be shown on errors. IfFalse
, only the summary of the traceback will be shown. In either case the program execution will stop on error. DefaultFalse
.cls (
Type
[TracebackHandler
]) – The class to use to handle the tracebacks. Defaultconsolekit.tracebacks.TracebackHandler
.
- Return type
Changed in version 1.0.0: Added the
cls
parameter.See also
-
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.
See also