Skip to content

Commit bed5545

Browse files
committed
Cleanup
1 parent fa4cf5c commit bed5545

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/robotremoteserver.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -265,19 +265,17 @@ def __init__(self):
265265
self.data = {'status': 'FAIL'}
266266

267267
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)
269269
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):
281279
name = exc_type.__name__
282280
message = self._get_message_from_exception(exc_value)
283281
if not message:
@@ -288,16 +286,15 @@ def _get_error_message(self, exc_type, exc_value):
288286
return '%s: %s' % (name, message)
289287

290288
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
293290
try:
294291
msg = unicode(value)
295292
except UnicodeError:
296293
msg = ' '.join(self._str(a, handle_binary=False) for a in value.args)
297294
return self._handle_binary_result(msg)
298295

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
301298
entries = traceback.extract_tb(exc_tb)[1:]
302299
trace = ''.join(traceback.format_list(entries))
303300
return 'Traceback (most recent call last):\n' + trace
@@ -306,7 +303,9 @@ def _get_error_attribute(self, exc_value, name):
306303
return bool(getattr(exc_value, 'ROBOT_%s_ON_FAILURE' % name, False))
307304

308305
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
310309

311310
def _handle_return_value(self, ret):
312311
if isinstance(ret, (str, unicode, bytes)):

0 commit comments

Comments
 (0)