Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improve exception diagnostics

  • Loading branch information...
commit 29e5a20520816e0170bfa293d1dcdc352a5cd177 1 parent a60e402
@batterseapower batterseapower authored
Showing with 12 additions and 3 deletions.
  1. +3 −1 pinyin/forms/builddbcontroller.py
  2. +9 −2 pinyin/utils.py
View
4 pinyin/forms/builddbcontroller.py
@@ -50,10 +50,12 @@ def __init__(self, view, notifier, dbbuilder, compulsory):
# Create and run a thread that just constructs the database
class Worker(QThread):
def run(self):
+ # NB: do not use suppressexceptions because throwing an exception at this point
+ # can cause segfaults in PyQt4 -- we better suppress the exception for developers too!
try:
dbbuilder.build()
self.emit(SIGNAL("buildsuccess()"))
- except Exception, e:
+ except:
log.exception("Suppressed exception in database build process")
self.emit(SIGNAL("buildfailure(PyQt_PyObject)"), sys.exc_info())
View
11 pinyin/utils.py
@@ -36,13 +36,16 @@ def suppressexceptions(action):
if debugmode():
# Don't suppress exceptions for the developers!
action()
+ return True
else:
try:
action()
+ return True
except:
# NB: have to delay the import of logger because it depends on utils
from logger import log
log.exception("Had to suppress an exception")
+ return False
"""
Utility function that reports whether a string consists only of punctuation character
@@ -181,18 +184,22 @@ def __init__(self, function):
self.__called = False
self.__result = None
self.__function = function
+
+ # For error messages only:
+ import traceback
+ self.__thunk_stack = traceback.format_stack()
def __call__(self):
if self.__called:
return self.__result
elif self.__called is None:
- raise ValueError("A thunked computation entered a black hole")
+ raise ValueError("A thunked computation entered a black hole! Created at:\n" + "".join(self.__thunk_stack))
try:
self.__called = None # Indicates that this thunk has become a black hole
self.__result = self.__function()
self.__called = True
- except Exception, e:
+ except:
from pinyin.logger import log
# Thunked actions raising an exception is a massively bad idea, because there
# is no way to know whose exception handler will be on the stack at the time we
Please sign in to comment.
Something went wrong with that request. Please try again.