@@ -265,19 +265,17 @@ def __init__(self):
265
265
self .data = {'status' : 'FAIL' }
266
266
267
267
def set_error (self , exc_type , exc_value , exc_tb = None ):
268
- self ._add ( 'error' , self ._get_error_message (exc_type , exc_value ) )
268
+ self .data [ 'error' ] = self ._get_message (exc_type , exc_value )
269
269
if exc_tb :
270
- self ._add ('traceback' , self ._get_error_traceback (exc_tb ))
271
- self ._add ('continuable' , self ._get_error_attribute (exc_value , 'CONTINUE' ),
272
- default = False )
273
- self ._add ('fatal' , self ._get_error_attribute (exc_value , 'EXIT' ),
274
- default = False )
275
-
276
- def _add (self , key , value , default = '' ):
277
- if value != default :
278
- self .data [key ] = value
279
-
280
- def _get_error_message (self , exc_type , exc_value ):
270
+ self .data ['traceback' ] = self ._get_traceback (exc_tb )
271
+ continuable = self ._get_error_attribute (exc_value , 'CONTINUE' )
272
+ if continuable :
273
+ self .data ['continuable' ] = continuable
274
+ fatal = self ._get_error_attribute (exc_value , 'EXIT' )
275
+ if fatal :
276
+ self .data ['fatal' ] = fatal
277
+
278
+ def _get_message (self , exc_type , exc_value ):
281
279
name = exc_type .__name__
282
280
message = self ._get_message_from_exception (exc_value )
283
281
if not message :
@@ -288,16 +286,15 @@ def _get_error_message(self, exc_type, exc_value):
288
286
return '%s: %s' % (name , message )
289
287
290
288
def _get_message_from_exception (self , value ):
291
- # UnicodeError occurs below 2.6 and if message contains non-ASCII bytes
292
- # TODO: Can try/except be removed here?
289
+ # UnicodeError occurs if message contains non-ASCII bytes
293
290
try :
294
291
msg = unicode (value )
295
292
except UnicodeError :
296
293
msg = ' ' .join (self ._str (a , handle_binary = False ) for a in value .args )
297
294
return self ._handle_binary_result (msg )
298
295
299
- def _get_error_traceback (self , exc_tb ):
300
- # Latest entry originates from this class so it can be removed
296
+ def _get_traceback (self , exc_tb ):
297
+ # Latest entry originates from this module so it can be removed
301
298
entries = traceback .extract_tb (exc_tb )[1 :]
302
299
trace = '' .join (traceback .format_list (entries ))
303
300
return 'Traceback (most recent call last):\n ' + trace
@@ -306,7 +303,9 @@ def _get_error_attribute(self, exc_value, name):
306
303
return bool (getattr (exc_value , 'ROBOT_%s_ON_FAILURE' % name , False ))
307
304
308
305
def set_return (self , value ):
309
- self ._add ('return' , self ._handle_return_value (value ))
306
+ value = self ._handle_return_value (value )
307
+ if value != '' :
308
+ self .data ['return' ] = value
310
309
311
310
def _handle_return_value (self , ret ):
312
311
if isinstance (ret , (str , unicode , bytes )):
0 commit comments