Skip to content

Commit

Permalink
Merge pull request #27 from cocolato/dev
Browse files Browse the repository at this point in the history
merge dev
  • Loading branch information
cocolato authored Mar 18, 2024
2 parents 40f0e1c + 942ac3b commit 15b561b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 12 additions & 0 deletions pydumpling/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import sys
from traceback import print_tb, print_exception
from .pydumpling import save_dumping


def print_traceback_and_except(dumpling_result):
Expand All @@ -10,3 +12,13 @@ def print_traceback_and_except(dumpling_result):
print_exception(exc_type, exc_value, exc_tb)
else:
print_tb(exc_tb)


def catch_any_exception():
original_hook = sys.excepthook

def _hook(exc_type, exc_value, exc_tb):
save_dumping(exc_info=(exc_type, exc_value, exc_tb))
original_hook(exc_type, exc_value, exc_tb) # call sys original hook

sys.excepthook = _hook
8 changes: 5 additions & 3 deletions pydumpling/pydumpling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
__version__ = "0.1.4"


def save_dumping(filename=None, tb=None):
def save_dumping(filename=None, exc_info=None):
try:
if tb is None:
if exc_info is None:
exc_type, exc_value, exc_tb = sys.exc_info()
else:
exc_type, exc_value, exc_tb = exc_info

if filename is None:
filename = "%s:%d.dump" % (
filename = "%s-%d.dump" % (
exc_tb.tb_frame.f_code.co_filename, exc_tb.tb_frame.f_lineno)

fake_tb = FakeTraceback(exc_tb)
Expand Down

0 comments on commit 15b561b

Please sign in to comment.