Crashtest
Crashtest is a Python library designed to simplify the handling and inspection of exceptions, providing tools to manage Python errors with ease. It is currently at version 0.4.1 and has a moderate release cadence, with recent updates focused on stability and type hinting.
Warnings
- breaking Crashtest versions 0.4.0 and newer require Python 3.7 or higher. Users on Python 3.6 or older will encounter compatibility issues when upgrading.
- gotcha Version 0.4.0 introduced stricter type hinting. A 'too narrow type' in the `Inspector` class was fixed in 0.4.1, suggesting that `0.4.0` might have introduced new type-related errors if existing code passed unexpected types.
- gotcha Prior to version 0.4.0, `crashtest` could encounter decoding errors when opening files due to the lack of explicit 'utf-8' encoding.
- gotcha In versions prior to 0.3.1, there was an error when attempting to retrieve the line of a frame if it had no context.
Install
-
pip install crashtest
Imports
- Inspector
from crashtest import Inspector
- ErrorHandler
from crashtest import ErrorHandler
Quickstart
import sys
from crashtest import Inspector
def might_fail():
a = 1
b = 0
return a / b
try:
might_fail()
except Exception as e:
inspector = Inspector(e)
print(f"Exception type: {inspector.type}")
print(f"Exception message: {inspector.message}")
print("Stack Trace:")
for frame in inspector.frames:
print(f" File: {frame.file}, Line: {frame.lineno}, Function: {frame.name}")
print(f" Code: {frame.line.strip() if frame.line else 'N/A'}")