2626)
2727
2828from Orange .util import try_
29-
29+ from Orange . canvas . scheme import Scheme
3030try :
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 (' ' , ' ' )),
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
0 commit comments