23 from .platform
import JYTHON, RERAISED_EXCEPTIONS
24 from .unic
import unic
27 EXCLUDE_ROBOT_TRACES =
not os.getenv(
'ROBOT_INTERNAL_TRACES')
29 from java.io
import StringWriter, PrintWriter
30 from java.lang
import Throwable, OutOfMemoryError
47 details =
ErrorDetails(exclude_robot_traces=exclude_robot_traces)
48 return details.message, details.traceback
57 def ErrorDetails(exc_info=None, exclude_robot_traces=EXCLUDE_ROBOT_TRACES):
58 exc_type, exc_value, exc_traceback = exc_info
or sys.exc_info()
59 if exc_type
in RERAISED_EXCEPTIONS:
61 details = PythonErrorDetails \
62 if not isinstance(exc_value, Throwable)
else JavaErrorDetails
63 return details(exc_type, exc_value, exc_traceback, exclude_robot_traces)
70 _generic_exception_names = (
'AssertionError',
'AssertionFailedError',
71 'Exception',
'Error',
'RuntimeError',
74 def __init__(self, exc_type, exc_value, exc_traceback,
75 exclude_robot_traces=True):
92 raise NotImplementedError
103 raise NotImplementedError
107 return exc_type.__name__
108 except AttributeError:
109 return unic(exc_type)
112 message =
unic(message
or '')
114 name = name.split(
'.')[-1]
119 return '%s: %s' % (name, message)
123 isinstance(self.
errorerror, RobotError)
or
124 getattr(self.
errorerror,
'ROBOT_SUPPRESS_NAME',
False))
137 if isinstance(self.
errorerror, RobotError):
138 return self.
errorerror.details
139 return 'Traceback (most recent call last):\n' + self.
_get_traceback_get_traceback()
145 return ''.join(traceback.format_tb(tb)).rstrip()
or ' None'
150 module = traceback.tb_frame.f_globals.get(
'__name__')
151 return module
and module.startswith(
'robot.')
158 _java_trace_re = re.compile(
'^\s+at (\w.+)')
162 _ignored_java_trace = (
'org.python.',
'robot.running.',
'robot$py.',
163 'sun.reflect.',
'java.lang.reflect.')
169 exc_msg = self.
errorerror.getMessage()
171 exc_msg = str(self.
errorerror)
175 return exc_type
is OutOfMemoryError
181 output = StringWriter()
182 self.
errorerror.printStackTrace(PrintWriter(output))
183 details =
'\n'.join(line
for line
in output.toString().splitlines()
185 msg =
unic(self.
errorerror.getMessage()
or '')
187 details = details.replace(msg,
'', 1)
196 location = res.group(1)
198 if location.startswith(entry):
207 lines = msg.splitlines()
213 return '\n'.join(lines)
216 tokens = msg.split(
':', 1)
217 if len(tokens) == 2
and tokens[0] == name:
def _is_ignored_stack_trace_line(self, line)
def _is_out_of_memory_error(self, exc_type)
def _remove_exception_name(self, msg, name)
def _remove_stack_trace_lines(self, msg)
def _clean_up_message(self, msg, name)
tuple _ignored_java_trace
def _is_excluded_traceback(self, traceback)
def _format_message(self, name, message)
def _is_generic_exception(self, name)
def _clean_up_message(self, message, name)
def __init__(self, exc_type, exc_value, exc_traceback, exclude_robot_traces=True)
tuple _generic_exception_names
def _get_name(self, exc_type)
def ErrorDetails(exc_info=None, exclude_robot_traces=EXCLUDE_ROBOT_TRACES)
This factory returns an object that wraps the last occurred exception.
def get_error_message()
Returns error message of the last occurred exception.
def get_error_details(exclude_robot_traces=EXCLUDE_ROBOT_TRACES)
Returns error message and details of the last occurred exception.