Skip to content

Commit

Permalink
added traceback of exception or full call stack if exception isn't ac…
Browse files Browse the repository at this point in the history
…tive
  • Loading branch information
YektaY committed Oct 25, 2024
1 parent 72ccb78 commit ecab60a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/badger/errors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from PyQt5.QtWidgets import QMessageBox
import traceback
import sys

class BadgerError(Exception):
def __init__(self, message="", detailed_text=""):
def __init__(self, message="", detailed_text=None):
if detailed_text is None:
detailed_text = self.capture_traceback_or_stack()

super().__init__(message)
self.detailed_text = detailed_text
self.show_message_box()
Expand All @@ -17,6 +22,17 @@ def show_message_box(self):
dialog.setIcon(QMessageBox.Critical)
dialog.exec_()

def capture_traceback_or_stack(self):
"""
Captures the current traceback if an exception is active, otherwise captures the call stack.
"""
exc_type, exc_value, exc_traceback = sys.exc_info()
if exc_traceback:
return ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback))
else:
return ''.join(traceback.format_stack())



class BadgerConfigError(BadgerError):
pass
Expand Down

0 comments on commit ecab60a

Please sign in to comment.