offline-debug 0.2.1__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {offline_debug-0.2.1 → offline_debug-0.3.0}/PKG-INFO +30 -5
- {offline_debug-0.2.1 → offline_debug-0.3.0}/README.md +29 -4
- offline_debug-0.3.0/offline_debug/__init__.py +14 -0
- {offline_debug-0.2.1 → offline_debug-0.3.0}/offline_debug/_inner/load_traceback.py +7 -0
- {offline_debug-0.2.1 → offline_debug-0.3.0}/offline_debug/_inner/models.py +8 -1
- {offline_debug-0.2.1 → offline_debug-0.3.0}/offline_debug/_inner/save_traceback.py +15 -3
- {offline_debug-0.2.1 → offline_debug-0.3.0}/pyproject.toml +1 -1
- offline_debug-0.2.1/offline_debug/__init__.py +0 -7
- {offline_debug-0.2.1 → offline_debug-0.3.0}/offline_debug/_inner/__init__.py +0 -0
- {offline_debug-0.2.1 → offline_debug-0.3.0}/offline_debug/_inner/c_api/__init__.py +0 -0
- {offline_debug-0.2.1 → offline_debug-0.3.0}/offline_debug/_inner/c_api/_create_frame.py +0 -0
- {offline_debug-0.2.1 → offline_debug-0.3.0}/offline_debug/_inner/c_api/_link_frame.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: offline-debug
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Debug exceptions offline by saving them to a dump and raising them at a later point.
|
|
5
5
|
Author: Itai Elidan
|
|
6
6
|
Author-email: Itai Elidan <itaielidan@gmail.com>
|
|
@@ -31,24 +31,49 @@ exceptions look and feel genuine to debuggers and introspection tools.
|
|
|
31
31
|
- `load_traceback(file: Path | BytesIO) -> Never`:
|
|
32
32
|
Loads the serialized state, reconstructs the exception and its full traceback chain (including `__cause__` and `__context__`),
|
|
33
33
|
and raises it.
|
|
34
|
+
- `parse_traceback(file: Path | BytesIO) -> ExceptionData`:
|
|
35
|
+
Loads the serialized data and returns an `ExceptionData` object. This allows for inspecting the exception, stack frames, and variables without reconstructing the full traceback or raising the exception.
|
|
34
36
|
|
|
35
37
|
## Usage Example
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
To get started, install with:
|
|
38
40
|
`pip install offline-debug` or `uv add offline-debug`
|
|
39
41
|
|
|
40
42
|
```python
|
|
41
43
|
from pathlib import Path
|
|
42
|
-
from offline_debug import save_traceback, load_traceback
|
|
44
|
+
from offline_debug import save_traceback, load_traceback, parse_traceback
|
|
43
45
|
|
|
46
|
+
# --- Saving an exception ---
|
|
44
47
|
try:
|
|
45
|
-
# Code that might fail
|
|
46
48
|
some_complex_operation()
|
|
47
49
|
except Exception as e:
|
|
48
50
|
save_traceback(e, Path("crash_report.dump"))
|
|
49
51
|
|
|
50
|
-
#
|
|
52
|
+
# --- Option 1: Re-raise the exception for debugging ---
|
|
53
|
+
# This will look like the original crash in your debugger
|
|
51
54
|
load_traceback(Path("crash_report.dump"))
|
|
55
|
+
|
|
56
|
+
# --- Option 2: Inspect data without raising ---
|
|
57
|
+
data = parse_traceback(Path("crash_report.dump"))
|
|
58
|
+
print(f"Number of frames: {len(data.tb_frames)}")
|
|
59
|
+
for frame in data.tb_frames:
|
|
60
|
+
print(f"File: {frame.code.co_filename}, Line: {frame.lineno}")
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Exception Group Support
|
|
64
|
+
|
|
65
|
+
`offline-debug` has full support for `ExceptionGroup` (Python 3.11+). When you parse a saved `ExceptionGroup`, you can access its nested exceptions:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from offline_debug import parse_traceback, ExceptionGroupData
|
|
69
|
+
|
|
70
|
+
data = parse_traceback(Path("exception_group.dump"))
|
|
71
|
+
|
|
72
|
+
if isinstance(data, ExceptionGroupData):
|
|
73
|
+
print(f"Group contains {len(data.exceptions)} sub-exceptions")
|
|
74
|
+
for sub_exc_data in data.exceptions:
|
|
75
|
+
# Each sub_exc_data is itself an ExceptionData object
|
|
76
|
+
print(f"Sub-exception frames: {len(sub_exc_data.tb_frames)}")
|
|
52
77
|
```
|
|
53
78
|
|
|
54
79
|
## Technical Implementation
|
|
@@ -19,24 +19,49 @@ exceptions look and feel genuine to debuggers and introspection tools.
|
|
|
19
19
|
- `load_traceback(file: Path | BytesIO) -> Never`:
|
|
20
20
|
Loads the serialized state, reconstructs the exception and its full traceback chain (including `__cause__` and `__context__`),
|
|
21
21
|
and raises it.
|
|
22
|
+
- `parse_traceback(file: Path | BytesIO) -> ExceptionData`:
|
|
23
|
+
Loads the serialized data and returns an `ExceptionData` object. This allows for inspecting the exception, stack frames, and variables without reconstructing the full traceback or raising the exception.
|
|
22
24
|
|
|
23
25
|
## Usage Example
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
To get started, install with:
|
|
26
28
|
`pip install offline-debug` or `uv add offline-debug`
|
|
27
29
|
|
|
28
30
|
```python
|
|
29
31
|
from pathlib import Path
|
|
30
|
-
from offline_debug import save_traceback, load_traceback
|
|
32
|
+
from offline_debug import save_traceback, load_traceback, parse_traceback
|
|
31
33
|
|
|
34
|
+
# --- Saving an exception ---
|
|
32
35
|
try:
|
|
33
|
-
# Code that might fail
|
|
34
36
|
some_complex_operation()
|
|
35
37
|
except Exception as e:
|
|
36
38
|
save_traceback(e, Path("crash_report.dump"))
|
|
37
39
|
|
|
38
|
-
#
|
|
40
|
+
# --- Option 1: Re-raise the exception for debugging ---
|
|
41
|
+
# This will look like the original crash in your debugger
|
|
39
42
|
load_traceback(Path("crash_report.dump"))
|
|
43
|
+
|
|
44
|
+
# --- Option 2: Inspect data without raising ---
|
|
45
|
+
data = parse_traceback(Path("crash_report.dump"))
|
|
46
|
+
print(f"Number of frames: {len(data.tb_frames)}")
|
|
47
|
+
for frame in data.tb_frames:
|
|
48
|
+
print(f"File: {frame.code.co_filename}, Line: {frame.lineno}")
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Exception Group Support
|
|
52
|
+
|
|
53
|
+
`offline-debug` has full support for `ExceptionGroup` (Python 3.11+). When you parse a saved `ExceptionGroup`, you can access its nested exceptions:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from offline_debug import parse_traceback, ExceptionGroupData
|
|
57
|
+
|
|
58
|
+
data = parse_traceback(Path("exception_group.dump"))
|
|
59
|
+
|
|
60
|
+
if isinstance(data, ExceptionGroupData):
|
|
61
|
+
print(f"Group contains {len(data.exceptions)} sub-exceptions")
|
|
62
|
+
for sub_exc_data in data.exceptions:
|
|
63
|
+
# Each sub_exc_data is itself an ExceptionData object
|
|
64
|
+
print(f"Sub-exception frames: {len(sub_exc_data.tb_frames)}")
|
|
40
65
|
```
|
|
41
66
|
|
|
42
67
|
## Technical Implementation
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Tool for serializing and reconstructing Python exceptions with full stack traces."""
|
|
2
|
+
|
|
3
|
+
from ._inner.load_traceback import load_traceback, parse_traceback
|
|
4
|
+
from ._inner.models import ExceptionData, ExceptionGroupData, FrameData
|
|
5
|
+
from ._inner.save_traceback import save_traceback
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"ExceptionData",
|
|
9
|
+
"ExceptionGroupData",
|
|
10
|
+
"FrameData",
|
|
11
|
+
"load_traceback",
|
|
12
|
+
"parse_traceback",
|
|
13
|
+
"save_traceback",
|
|
14
|
+
]
|
|
@@ -14,6 +14,7 @@ from offline_debug._inner.c_api import (
|
|
|
14
14
|
)
|
|
15
15
|
from offline_debug._inner.models import (
|
|
16
16
|
ExceptionData,
|
|
17
|
+
ExceptionGroupData,
|
|
17
18
|
FrameData,
|
|
18
19
|
)
|
|
19
20
|
|
|
@@ -36,6 +37,12 @@ def _reconstruct_exc_data(data: ExceptionData) -> BaseException:
|
|
|
36
37
|
msg = f"Expected BaseException, but got {type(exc).__name__}"
|
|
37
38
|
raise TypeError(msg)
|
|
38
39
|
|
|
40
|
+
if isinstance(data, ExceptionGroupData) and isinstance(exc, BaseExceptionGroup):
|
|
41
|
+
inner_excs = [_reconstruct_exc_data(e) for e in data.exceptions]
|
|
42
|
+
# We must use derive to create a new ExceptionGroup with reconstructed inner exceptions.
|
|
43
|
+
# The exceptions that are inside the unpickled exc object are have incomplete data.
|
|
44
|
+
exc = exc.derive(inner_excs)
|
|
45
|
+
|
|
39
46
|
reconstructed_frames: list[tuple[types.FrameType, FrameData]] = []
|
|
40
47
|
for f_data in data.tb_frames:
|
|
41
48
|
code: CodeType = marshal.loads(f_data.code) # noqa: S302
|
|
@@ -19,7 +19,7 @@ class FrameData:
|
|
|
19
19
|
module_name: str | None = None
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
@dataclass
|
|
22
|
+
@dataclass(kw_only=True)
|
|
23
23
|
class ExceptionData:
|
|
24
24
|
"""Serialized data for an exception and its traceback."""
|
|
25
25
|
|
|
@@ -27,3 +27,10 @@ class ExceptionData:
|
|
|
27
27
|
tb_frames: list[FrameData]
|
|
28
28
|
cause: ExceptionData | None = None
|
|
29
29
|
context: ExceptionData | None = None
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass(kw_only=True)
|
|
33
|
+
class ExceptionGroupData(ExceptionData):
|
|
34
|
+
"""Serialized data for an ExceptionGroup."""
|
|
35
|
+
|
|
36
|
+
exceptions: list[ExceptionData]
|
|
@@ -6,7 +6,7 @@ import types
|
|
|
6
6
|
from io import BytesIO
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
|
|
9
|
-
from offline_debug._inner.models import ExceptionData, FrameData
|
|
9
|
+
from offline_debug._inner.models import ExceptionData, ExceptionGroupData, FrameData
|
|
10
10
|
|
|
11
11
|
# Internal attributes that are either unpicklable or redundant in a new process.
|
|
12
12
|
# We exclude these specifically because they are automatically recreated
|
|
@@ -77,11 +77,23 @@ def _serialize_exc_data(exc: BaseException) -> ExceptionData:
|
|
|
77
77
|
RuntimeError(f"Unpicklable exception {type(exc).__name__}: {exc!s}")
|
|
78
78
|
)
|
|
79
79
|
|
|
80
|
+
cause = _serialize_exc_data(exc.__cause__) if exc.__cause__ else None
|
|
81
|
+
context = _serialize_exc_data(exc.__context__) if exc.__context__ else None
|
|
82
|
+
|
|
83
|
+
if isinstance(exc, BaseExceptionGroup):
|
|
84
|
+
return ExceptionGroupData(
|
|
85
|
+
exc_pickle=exc_pickle,
|
|
86
|
+
tb_frames=tb_frames,
|
|
87
|
+
cause=cause,
|
|
88
|
+
context=context,
|
|
89
|
+
exceptions=[_serialize_exc_data(e) for e in exc.exceptions],
|
|
90
|
+
)
|
|
91
|
+
|
|
80
92
|
return ExceptionData(
|
|
81
93
|
exc_pickle=exc_pickle,
|
|
82
94
|
tb_frames=tb_frames,
|
|
83
|
-
cause=
|
|
84
|
-
context=
|
|
95
|
+
cause=cause,
|
|
96
|
+
context=context,
|
|
85
97
|
)
|
|
86
98
|
|
|
87
99
|
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"""Tool for serializing and reconstructing Python exceptions with full stack traces."""
|
|
2
|
-
|
|
3
|
-
from ._inner.load_traceback import load_traceback, parse_traceback
|
|
4
|
-
from ._inner.models import ExceptionData, FrameData
|
|
5
|
-
from ._inner.save_traceback import save_traceback
|
|
6
|
-
|
|
7
|
-
__all__ = ["ExceptionData", "FrameData", "load_traceback", "parse_traceback", "save_traceback"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|