API

dump_exception(exc, filename='traceback.pkl', start_from=None)

Dump exception object and corresponding crash information into a file.

Parameters:

Name Type Description Default
exc Exception

Exception object with traceback.

required
filename str

Target file name or path.

'traceback.pkl'
start_from str

Name of the source file to be considered as topmost.

None
Source code in tibidi/dumper.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def dump_exception(exc: Exception, filename: str = DEFAULT_DUMP_NAME,
                   start_from: str = None) -> None:
    """Dump exception object and corresponding crash information into a file.

    Arguments:
        exc: Exception object with traceback.
        filename: Target file name or path.
        start_from: Name of the source file to be considered as topmost.
    """

    report = report_header()
    report['exceptions'] = exception_stack_info(exc)
    if start_from:
        last_exc = report['exceptions'][-1]
        while last_exc:
            if last_exc[0]._filename == start_from:
                break
            del last_exc[0]

    with open(filename, 'wb') as f:
        pickler.dump(report, f)

set_excepthook(filename='traceback.pkl', replace=True, silent=False)

Install tbdump as an exception handler.

Parameters:

Name Type Description Default
filename str

File name or path to the dump file.

'traceback.pkl'
replace bool

Set False to call original exception handler after tbdump.

True
silent bool

Set True to suppress messages.

False
Source code in tibidi/dumper.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def set_excepthook(filename: str = DEFAULT_DUMP_NAME, replace: bool = True,
                   silent: bool = False) -> None:
    """Install tbdump as an exception handler.

    Arguments:
        filename: File name or path to the dump file.
        replace: Set `False` to call original exception handler after tbdump.
        silent: Set `True` to suppress messages.
    """

    old_excepthook = sys.excepthook

    if silent:
        say = lambda text: None
    else:
        say = lambda text: print(text, file=sys.stderr)

    def tbdump_except_hook(exctype, exc, traceback):
        say(exctype.__name__ + ': ' + str(exc))
        try:
            dump_exception(exc, filename)
            say('Traceback dumped into: ' + filename)
        except Exception:
            if config.debug:
                raise
            say('Failed to dump traceback')

        if not replace:
            old_excepthook(exctype, exc, traceback)

    sys.excepthook = tbdump_except_hook

load(filename='traceback.pkl')

Load crash information from a dump file.

Parameters:

Name Type Description Default
filename str

File name or path to be loded.

'traceback.pkl'

Returns:

Type Description
dict

Crash information.

Source code in tibidi/loader.py
42
43
44
45
46
47
48
49
50
51
52
53
def load(filename: str = DEFAULT_DUMP_NAME) -> dict:
    """Load crash information from a dump file.

    Arguments:
        filename: File name or path to be loded.

    Returns:
        Crash information.
    """
    with DummyModuleFactory():
        with open(filename, 'rb') as f:
            return pickler.load(f)