Skip to content

Commit

Permalink
hotfix co_qualname not available & safer sys exception
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianCert committed Jun 5, 2024
1 parent 099a8ec commit c4f7461
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 15 deletions.
13 changes: 12 additions & 1 deletion examples/example01.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import random

import snap4frame

import snap4frame.processor
import snap4frame.processor.kit

snap4frame.setup_handler(
"default",
[
snap4frame.processor.kit.FileSaveProcessor(
create_path=True,
exists_ok=True,
),
],
)
snap4frame.init()


Expand Down
File renamed without changes.
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "snap4frame"
version = "0.1.0"
version = "0.1.1"
description = "Creates a snapshot of the python program for later analysis"
authors = [
{ name = "Panaintescu Adrian Valentin", email = "[email protected]" },
Expand All @@ -9,8 +9,8 @@ dependencies = [
"importlib-metadata>=7.0.1",
]
requires-python = ">=3.8"
readme = "README.md"
license = { text = "GPL-3.0-or-later" }
readme = "readme.md"
license = { file = "license.md" }

[project.optional-dependencies]
"dev" = [
Expand All @@ -24,6 +24,7 @@ msgspec = [
requests = [
"requests>=2.31.0",
]

[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"
Expand Down
3 changes: 2 additions & 1 deletion README.md → readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# **snap4frame**

### creates a snapshot of the python program for later analysis

**snap4frame** is a python package that creates a snapshot of your python program for later analysis. It's designed to help developers understand the state of their program at a specific point in time, which can be useful for debugging and performance optimization.
Expand Down Expand Up @@ -50,4 +51,4 @@ We welcome contributions to snap4frame! Please see our [contributing guide](CONT

## License

Snap4frame is licensed under the [MIT License](LICENSE).
Snap4frame is licensed under the [MIT License](license.md).
4 changes: 2 additions & 2 deletions src/snap4frame/core/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TracebackFrameDecoder(TracebackDecoder):
config: types.Parameters = types.Parameters(config.FRAME_DECODER)

def decode(self, data: TracebackType):
frame_name = data.tb_frame.f_code.co_qualname
frame_name = data.tb_frame.f_code.co_name
frame_file = Path(data.tb_frame.f_code.co_filename)

frame_locals = data.tb_frame.f_locals
Expand Down Expand Up @@ -53,7 +53,7 @@ def decode(self, data: Optional[TracebackType]):

iter_stack: Iterator[TracebackType] = reversed(raw_stack)
for tb_obj in iter_stack:
frame_name = tb_obj.tb_frame.f_code.co_qualname
frame_name = tb_obj.tb_frame.f_code.co_name

if self.config.exclude_frames and any(
fnmatch(frame_name, pth) for pth in self.config.exclude_frames
Expand Down
19 changes: 11 additions & 8 deletions src/snap4frame/core/handlers/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ def handle_exception(
Returns:
None
"""
traceback = exception.__traceback__
stacktrace = list(self.traceback_decoder.decode(traceback))
report = SnapFrameReport(
stacktrace=stacktrace,
context=self.context_reporter(),
value=str(exception),
)
try:
traceback = exception.__traceback__
stacktrace = list(self.traceback_decoder.decode(traceback))
report = SnapFrameReport(
stacktrace=stacktrace,
context=self.context_reporter(),
value=str(exception),
)

return self.event_handler.emit(report, kind=kind)
return self.event_handler.emit(report, kind=kind)
except Exception:
pass

def exception_hook(self, type, value, traceback):
"""
Expand Down

0 comments on commit c4f7461

Please sign in to comment.