Skip to content

Commit 77a6cbf

Browse files
committed
errorreporting: Remove explicit canvas window parameter to ExceptHook
Try to retrieve the workflow file via the OWWidget instance extracted from the stack.
1 parent 0b8240c commit 77a6cbf

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

Orange/canvas/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ def show_message(message):
484484
log.info("Entering main event loop.")
485485
try:
486486
with patch('sys.excepthook',
487-
ExceptHook(stream=stderr, canvas=canvas_window,
487+
ExceptHook(stream=stderr,
488488
handledException=handle_exception)),\
489489
patch('sys.stderr', stderr),\
490490
patch('sys.stdout', stdout):

Orange/canvas/application/errorreporting.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
)
2727

2828
from Orange.util import try_
29-
29+
from Orange.canvas.scheme import Scheme
3030
try:
3131
from Orange.widgets.widget import OWWidget
3232
from Orange.version import full_version as VERSION_STR
@@ -179,7 +179,7 @@ def _post_report(data):
179179
@patch('sys.excepthook', sys.__excepthook__) # Prevent recursion
180180
@pyqtSlot(object)
181181
def handle_exception(cls, exc):
182-
(etype, evalue, tb), canvas = exc
182+
etype, evalue, tb = exc
183183
exception = traceback.format_exception_only(etype, evalue)[-1].strip()
184184
stacktrace = ''.join(traceback.format_exception(etype, evalue, tb))
185185

@@ -204,10 +204,19 @@ def _find_widget_frame(tb):
204204
return tb
205205
tb = tb.tb_next
206206

207-
widget_module, widget, frame = None, None, _find_widget_frame(tb)
208-
if frame:
209-
widget = frame.tb_frame.f_locals['self'].__class__
210-
widget_module = '{}:{}'.format(widget.__module__, frame.tb_lineno)
207+
widget_module = widget_class = widget = workflow = None
208+
frame = _find_widget_frame(tb)
209+
if frame is not None:
210+
widget = frame.tb_frame.f_locals['self'] # type: OWWidget
211+
widget_class = widget.__class__
212+
widget_module = '{}:{}'.format(widget_class.__module__, frame.tb_lineno)
213+
if widget is not None:
214+
try:
215+
workflow = widget.signalManager.parent()
216+
if not isinstance(workflow, Scheme):
217+
raise TypeError
218+
except Exception:
219+
workflow = None
211220

212221
packages = ', '.join(sorted(get_installed_distributions()))
213222

@@ -218,7 +227,8 @@ def _find_widget_frame(tb):
218227
if (err_module, widget_module) in cls._cache:
219228
QMessageBox(QMessageBox.Warning, 'Error Encountered',
220229
'Error encountered{}:<br><br><tt>{}</tt>'.format(
221-
' in widget <b>{}</b>'.format(widget.name) if widget else '',
230+
(' in widget <b>{}</b>'.format(widget_class.name)
231+
if widget_class else ''),
222232
stacktrace.replace('\n', '<br>').replace(' ', '&nbsp;')),
223233
QMessageBox.Ignore).exec()
224234
return
@@ -227,19 +237,15 @@ def _find_widget_frame(tb):
227237
data = OrderedDict()
228238
data[F.EXCEPTION] = exception
229239
data[F.MODULE] = err_module
230-
if widget:
231-
data[F.WIDGET_NAME] = widget.name
240+
if widget_class is not None:
241+
data[F.WIDGET_NAME] = widget_class.name
232242
data[F.WIDGET_MODULE] = widget_module
233-
if canvas:
243+
if workflow is not None:
234244
fd, filename = mkstemp(prefix='ows-', suffix='.ows.xml')
235245
os.close(fd)
236-
# Prevent excepthook printing the same exception when
237-
# canvas tries to instantiate the broken widget again
238-
with patch('sys.excepthook', lambda *_: None), \
239-
open(filename, "wb") as f:
240-
scheme = canvas.current_document().scheme()
246+
with open(filename, "wb") as f:
241247
try:
242-
scheme.save_to(f, pretty=True, pickle_fallback=True)
248+
workflow.save_to(f, pretty=True, pickle_fallback=True)
243249
except Exception:
244250
pass
245251
data[F.WIDGET_SCHEME] = filename

Orange/canvas/application/outputview.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,9 @@ def flush(self):
245245
class ExceptHook(QObject):
246246
handledException = Signal(object)
247247

248-
def __init__(self, parent=None, stream=None, canvas=None, **kwargs):
248+
def __init__(self, parent=None, stream=None, **kwargs):
249249
QObject.__init__(self, parent, **kwargs)
250250
self._stream = stream
251-
self._canvas = canvas
252251

253252
def __call__(self, exc_type, exc_value, tb):
254253
if self._stream:
@@ -260,4 +259,4 @@ def __call__(self, exc_type, exc_value, tb):
260259
text.append('-' * 79 + '\n')
261260
self._stream.writelines(text)
262261

263-
self.handledException.emit(((exc_type, exc_value, tb), self._canvas))
262+
self.handledException.emit((exc_type, exc_value, tb))

0 commit comments

Comments
 (0)