[pytango] 65/483: fixed problem in exception report

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:14:25 UTC 2017


This is an automated email from the git hooks/post-receive script.

sbodomerle-guest pushed a commit to annotated tag bliss_8.10
in repository pytango.

commit 70e28e76ab92b95c5e6d47d6a19ec13d0b8dd0f5
Author: tiagocoutinho <tiagocoutinho at 4e9c00fd-8f2e-0410-aa12-93ce3db5e235>
Date:   Wed Nov 23 12:24:20 2011 +0000

    fixed problem in exception report
    
    git-svn-id: http://svn.code.sf.net/p/tango-cs/code/bindings/PyTango/trunk@18451 4e9c00fd-8f2e-0410-aa12-93ce3db5e235
---
 PyTango/exception.py |  39 ++++++++++--
 src/exception.cpp    | 173 ++++++++++++++++++++++++++++-----------------------
 src/exception.h      |   6 ++
 3 files changed, 136 insertions(+), 82 deletions(-)

diff --git a/PyTango/exception.py b/PyTango/exception.py
index 6c24be0..5aaacf9 100644
--- a/PyTango/exception.py
+++ b/PyTango/exception.py
@@ -32,6 +32,34 @@ __docformat__ = "restructuredtext"
 from utils import document_static_method as __document_static_method
 from _PyTango import Except, DevError
 
+def __to_dev_failed(exc_type=None, exc_value=None, traceback=None):
+    """to_dev_failed(exc_type, exc_value, traceback) -> PyTango.DevFailed
+
+            Generate a TANGO DevFailed exception.
+            The exception is created with a single :class:`~PyTango.DevError`
+            object. A default value *PyTango.ErrSeverity.ERR* is defined for
+            the :class:`~PyTango.DevError` severity field.
+            
+            The parameters are the same as the ones generates by a call to
+            :func:`sys.exc_info`.
+            
+        Parameters :
+            - type : (class)  the exception type of the exception being handled
+            - value : (object) exception parameter (its associated value or the
+                      second argument to raise, which is always a class instance
+                      if the exception type is a class object)
+            - traceback : (traceback) traceback object
+        
+        Return     : (PyTango.DevFailed) a tango exception object
+        
+        New in PyTango 7.2.1"""
+    try:
+        Except.throw_python_exception(exc_type, exc_value, traceback)
+    except Exception, e:
+        return e
+
+def __init_Except():
+    Except.to_dev_failed = staticmethod(__to_dev_failed)
 
 def __doc_Except():
     def document_static_method(method_name, desc, append=True):
@@ -97,26 +125,28 @@ def __doc_Except():
         Parameters :
             - ex     : (PyTango.DevFailed) The :class:`~PyTango.DevFailed` exception
     """ )
-
+    
     document_static_method("throw_python_exception", """
     throw_python_exception(type, value, traceback) -> None
 
             Generate and throw a TANGO DevFailed exception.
-            The exception is created with a single :class:`~PyTango.DevError` 
-            object. A default value *PyTango.ErrSeverity.ERR* is defined for 
+            The exception is created with a single :class:`~PyTango.DevError`
+            object. A default value *PyTango.ErrSeverity.ERR* is defined for
             the :class:`~PyTango.DevError` severity field.
             
             The parameters are the same as the ones generates by a call to
             :func:`sys.exc_info`.
             
         Parameters :
-            - type : (class)  the exception type of the exception being handled 
+            - type : (class)  the exception type of the exception being handled
             - value : (object) exception parameter (its associated value or the
                       second argument to raise, which is always a class instance
                       if the exception type is a class object)
             - traceback : (traceback) traceback object
 
         Throws     : DevFailed
+        
+        New in PyTango 7.2.1
     """ )
     
 def __doc_DevError():
@@ -131,6 +161,7 @@ def __doc_DevError():
 
   
 def init(doc=True):
+    __init_Except()
     if doc:
         __doc_Except()
         __doc_DevError()
\ No newline at end of file
diff --git a/src/exception.cpp b/src/exception.cpp
index 5b9902e..218be7c 100644
--- a/src/exception.cpp
+++ b/src/exception.cpp
@@ -122,7 +122,7 @@ void throw_python_dev_failed()
 
     if (value == NULL)
     {
-        Py_DECREF(type);
+        Py_XDECREF(type);
         Py_XDECREF(traceback);
 
         Tango::Except::throw_exception(
@@ -138,116 +138,126 @@ void throw_python_dev_failed()
     }
     catch(...)
     {
-        Py_DECREF(type);
-        Py_DECREF(value);
+        Py_XDECREF(type);
+        Py_XDECREF(value);
         Py_XDECREF(traceback);
         throw;
     }
 
-    Py_DECREF(type);
-    Py_DECREF(value);
+    Py_XDECREF(type);
+    Py_XDECREF(value);
     Py_XDECREF(traceback);
 
     throw df;
 }
 
-void throw_python_generic_exception(PyObject *type, PyObject *value,
-                                    PyObject *traceback)
+Tango::DevFailed to_dev_failed(PyObject *type, PyObject *value,
+                               PyObject *traceback)
 {
-    if ((type == NULL) || (value == NULL) || (traceback == NULL))
+    bool from_fetch = false;
+    if ((type == NULL) || (value == NULL) || (traceback == NULL) ||
+        (type == Py_None) || (value == Py_None) || (traceback == Py_None))
     {
         PyErr_Fetch(&type, &value, &traceback);
-    }
-    
-//
-// Send a default exception in case Python does not send us information
-//
-    if (value == NULL)
-    {
-        Py_XDECREF(type);
-        Py_XDECREF(value);
-        Py_XDECREF(traceback);
-
-        Tango::Except::throw_exception((const char *)"PyDs_BadPythonException",
-                (const char *)"A badly formed exception has been received",
-                (const char *)"Py_throw_dev_failed");
+        from_fetch = true;
     }
 
     Tango::DevErrorList dev_err;
     dev_err.length(1);
+    
 
-    //
-    // Populate a one level DevFailed exception
-    //
-
-    PyObject *tracebackModule = PyImport_ImportModule("traceback");
-    if (tracebackModule != NULL)
+    if (value == NULL)
     {
-        PyObject *tbList, *emptyString, *strRetval;
-
         //
-        // Format the traceback part of the Python exception
-        // and store it in the origin part of the Tango exception
+        // Send a default exception in case Python does not send us information
         //
+        dev_err[0].origin = CORBA::string_dup("Py_to_dev_failed");
+        dev_err[0].desc = CORBA::string_dup("A badly formed exception has been received");
+        dev_err[0].reason = CORBA::string_dup("PyDs_BadPythonException");
+        dev_err[0].severity = Tango::ERR;
+    }
+    else
+    {
+        //
+        // Populate a one level DevFailed exception
+        //
+
+        PyObject *tracebackModule = PyImport_ImportModule("traceback");
+        if (tracebackModule != NULL)
+        {
+            PyObject *tbList, *emptyString, *strRetval;
 
-        tbList = PyObject_CallMethod(
-                tracebackModule,
-                (char *)"format_tb",
-                (char *)"O",
-                traceback == NULL ? Py_None : traceback);
+            //
+            // Format the traceback part of the Python exception
+            // and store it in the origin part of the Tango exception
+            //
 
-        emptyString = PyString_FromString("");
-        strRetval = PyObject_CallMethod(emptyString, (char *)"join", (char *)"O", tbList);
+            tbList = PyObject_CallMethod(
+                    tracebackModule,
+                    (char *)"format_tb",
+                    (char *)"O",
+                    traceback == NULL ? Py_None : traceback);
 
-        dev_err[0].origin = CORBA::string_dup(PyString_AsString(strRetval));
+            emptyString = PyString_FromString("");
+            strRetval = PyObject_CallMethod(emptyString, (char *)"join", (char *)"O", tbList);
 
-        Py_DECREF(tbList);
-        Py_DECREF(emptyString);
-        Py_DECREF(strRetval);
+            dev_err[0].origin = CORBA::string_dup(PyString_AsString(strRetval));
 
-        //
-        // Format the exec and value part of the Python exception
-        // and store it in the desc part of the Tango exception
-        //
+            Py_DECREF(tbList);
+            Py_DECREF(emptyString);
+            Py_DECREF(strRetval);
 
-        tbList = PyObject_CallMethod(
-                tracebackModule,
-                (char *)"format_exception_only",
-                (char *)"OO",
-                type,
-                value == NULL ? Py_None : value);
+            //
+            // Format the exec and value part of the Python exception
+            // and store it in the desc part of the Tango exception
+            //
 
-        emptyString = PyString_FromString("");
-        strRetval = PyObject_CallMethod(emptyString, (char *)"join", (char *)"O", tbList);
+            tbList = PyObject_CallMethod(
+                    tracebackModule,
+                    (char *)"format_exception_only",
+                    (char *)"OO",
+                    type,
+                    value == NULL ? Py_None : value);
 
-        dev_err[0].desc = CORBA::string_dup(PyString_AsString(strRetval));
+            emptyString = PyString_FromString("");
+            strRetval = PyObject_CallMethod(emptyString, (char *)"join", (char *)"O", tbList);
 
-        Py_DECREF(tbList);
-        Py_DECREF(emptyString);
-        Py_DECREF(strRetval);
-        Py_DECREF(tracebackModule);
+            dev_err[0].desc = CORBA::string_dup(PyString_AsString(strRetval));
 
-        dev_err[0].reason = CORBA::string_dup("PyDs_PythonError");
-        dev_err[0].severity = Tango::ERR;
+            Py_DECREF(tbList);
+            Py_DECREF(emptyString);
+            Py_DECREF(strRetval);
+            Py_DECREF(tracebackModule);
+
+            dev_err[0].reason = CORBA::string_dup("PyDs_PythonError");
+            dev_err[0].severity = Tango::ERR;
+        }
+        else
+        {
+            //
+            // Send a default exception because we can't format the
+            // different parts of the Python's one !
+            //
+
+            dev_err[0].origin = CORBA::string_dup("Py_to_dev_failed");
+            dev_err[0].desc = CORBA::string_dup("Can't import Python traceback module. Can't extract info from Python exception");
+            dev_err[0].reason = CORBA::string_dup("PyDs_PythonError");
+            dev_err[0].severity = Tango::ERR;
+        }
     }
-    else
+    if(from_fetch)
     {
-        //
-        // Send a default exception because we can't format the
-        // different parts of the Python's one !
-        //
-
-        dev_err[0].origin = CORBA::string_dup("Py_throw_dev_failed");
-        dev_err[0].desc = CORBA::string_dup("Can't import Python traceback module. Can't extract info from Python exception");
-        dev_err[0].reason = CORBA::string_dup("PyDs_PythonError");
-        dev_err[0].severity = Tango::ERR;
+        Py_XDECREF(type);
+        Py_XDECREF(value);
+        Py_XDECREF(traceback);
     }
+    return Tango::DevFailed(dev_err);
+}
 
-    Py_XDECREF(type);
-    Py_XDECREF(value);
-    Py_XDECREF(traceback);
-
-    throw Tango::DevFailed(dev_err);
+void throw_python_generic_exception(PyObject *type, PyObject *value,
+                                    PyObject *traceback)
+{
+    throw to_dev_failed(type, value, traceback);
 }
 
 void handle_python_exception(boost::python::error_already_set &eas)
@@ -367,6 +377,10 @@ namespace PyNamedDevFailed
     }
 }
 
+//BOOST_PYTHON_FUNCTION_OVERLOADS(to_dev_failed_overloads, to_dev_failed, 0, 3)
+BOOST_PYTHON_FUNCTION_OVERLOADS(throw_python_generic_exception_overloads,
+                                throw_python_generic_exception, 0, 3)
+
 void export_exceptions()
 {
     bool (*compare_exception_) (Tango::DevFailed &, Tango::DevFailed &) = &Tango::Except::compare_exception;
@@ -447,11 +461,14 @@ void export_exceptions()
         .def("compare_exception",
             (bool (*) (const Tango::DevFailed &, const Tango::DevFailed &))
             compare_exception_)
-        .def("throw_python_exception", &throw_python_generic_exception)
+        //.def("to_dev_failed", &to_dev_failed, to_dev_failed_overloads())
+        .def("throw_python_exception", &throw_python_generic_exception,
+            throw_python_generic_exception_overloads())
         .staticmethod("throw_exception")
         .staticmethod("re_throw_exception")
         .staticmethod("print_exception")
         .staticmethod("print_error_stack")
+        //.staticmethod("to_dev_failed")
         .staticmethod("throw_python_exception")
     ;
 
diff --git a/src/exception.h b/src/exception.h
index 9c16761..be56e17 100644
--- a/src/exception.h
+++ b/src/exception.h
@@ -49,6 +49,12 @@ void PyDevFailed_2_DevFailed(PyObject *obj, Tango::DevFailed &df);
 void throw_python_dev_failed();
 
 /**
+ * Transforms a python exception into a Tango::DevFailed
+ */
+Tango::DevFailed to_dev_failed(PyObject *type=NULL, PyObject *value=NULL,
+                               PyObject *traceback=NULL);
+
+/**
  * Throws the current python exception as a DevFailed exception.
  */
 void throw_python_generic_exception(PyObject *type=NULL, PyObject *value=NULL,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/pytango.git



More information about the debian-science-commits mailing list