Revision: 3207
Author: janne.t.harkonen
Date: Thu May  6 00:51:55 2010
Log: Implemented error details as a class
http://code.google.com/p/robotframework/source/detail?r=3207

Modified:
 /trunk/src/robot/errors.py
 /trunk/src/robot/running/keywords.py
 /trunk/src/robot/utils/__init__.py
 /trunk/src/robot/utils/error.py

=======================================
--- /trunk/src/robot/errors.py  Wed May  5 23:54:49 2010
+++ /trunk/src/robot/errors.py  Thu May  6 00:51:55 2010
@@ -85,13 +85,15 @@

 class HandlerExecutionFailed(ExecutionFailed):

-    def __init__(self, message, orig_error, is_test_or_suite_teardown):
+    def __init__(self, error_details, is_test_or_suite_teardown):
+        orig_error = error_details.error
         timeout = isinstance(orig_error, TimeoutError)
         syntax = isinstance(orig_error, DataError)
         exit = bool(getattr(orig_error, 'ROBOT_EXIT_ON_FAILURE', False))
cont = bool(getattr(orig_error, 'ROBOT_CONTINUE_ON_FAILURE', False))
         cont = cont or is_test_or_suite_teardown
- ExecutionFailed.__init__(self, message, timeout, syntax, exit, cont) + ExecutionFailed.__init__(self, error_details.message, timeout, syntax,
+                                 exit, cont)


 class ExecutionFailures(ExecutionFailed):
=======================================
--- /trunk/src/robot/running/keywords.py        Wed May  5 23:54:49 2010
+++ /trunk/src/robot/running/keywords.py        Thu May  6 00:51:55 2010
@@ -98,11 +98,11 @@
             self._report_failure(output, namespace)

     def _report_failure(self, output, namespace):
- message, details, orig_error = utils.get_error_details_and_instance()
-        output.fail(message)
-        if details:
-            output.debug(details)
-        raise HandlerExecutionFailed(message, orig_error,
+        error_details = utils.ErrorDetails()
+        output.fail(error_details.message)
+        if error_details.traceback:
+            output.debug(error_details.traceback)
+        raise HandlerExecutionFailed(error_details,
self._in_test_or_suite_teardown(namespace))

     def _in_test_or_suite_teardown(self, namespace):
=======================================
--- /trunk/src/robot/utils/__init__.py  Wed May  5 23:54:49 2010
+++ /trunk/src/robot/utils/__init__.py  Thu May  6 00:51:55 2010
@@ -20,7 +20,7 @@
 from domwrapper import DomWrapper
 from escaping import escape, unescape, escape_file_name
from error import get_error_message, get_error_details, RERAISED_EXCEPTIONS, \
-    get_error_details_and_instance
+    ErrorDetails
 from htmlutils import html_escape, html_attr_escape
 from htmlwriter import HtmlWriter
 from importing import simple_import, import_
=======================================
--- /trunk/src/robot/utils/error.py     Wed May  5 23:54:49 2010
+++ /trunk/src/robot/utils/error.py     Thu May  6 00:51:55 2010
@@ -44,38 +44,40 @@
MUST be used to get messages from all exceptions originating outside the
     framework.
     """
-    exc_type, exc_value = sys.exc_info()[:2]
-    if exc_type in RERAISED_EXCEPTIONS:
-        raise exc_value
-    if _is_java_exception(exc_value):
-        return _get_java_message(exc_type, exc_value)
-    return _get_python_message(exc_type, exc_value)
+    return ErrorDetails().message


 def get_error_details():
     """Returns error message and details of the last occurred exception.
-
- Error message contains exception's type and message and details contains
-    stacktrace.
-
- This method handles also exceptions containing unicode messages. Thus it
+    """
+    dets = ErrorDetails()
+    return dets.message, dets.details
+
+
+class ErrorDetails(object):
+    """This class wraps the last occurred exception
+
+    It has attributes message, traceback and error, where message contains
+ type and message of the original error, traceback it's contains traceback + (or stack trace in case of Java exception) and error contains the original
+    error instance
+
+    This class handles also exceptions containing unicode messages. Thus it
MUST be used to get messages from all exceptions originating outside the
     framework.
     """
-    return get_error_details_and_instance()[:2]
-
-
-def get_error_details_and_instance():
-    exc_type, exc_value, exc_traceback = sys.exc_info()
-    if exc_type in (KeyboardInterrupt, SystemExit):
-        raise exc_value
-    if _is_java_exception(exc_value):
-        message = _get_java_message(exc_type, exc_value)
-        details = _get_java_details(exc_value)
-    else:
-        message = _get_python_message(exc_type, exc_value)
-        details = _get_python_details(exc_value, exc_traceback)
-    return message, details, exc_value
+
+    def __init__(self):
+        exc_type, exc_value, exc_traceback = sys.exc_info()
+        if exc_type in RERAISED_EXCEPTIONS:
+            raise exc_value
+        if _is_java_exception(exc_value):
+            self.message = _get_java_message(exc_type, exc_value)
+            self.traceback = _get_java_details(exc_value)
+        else:
+            self.message = _get_python_message(exc_type, exc_value)
+            self.traceback = _get_python_details(exc_value, exc_traceback)
+        self.error = exc_value


 def _is_java_exception(exc):

Reply via email to