Archived

This forum has been archived. Please start a new discussion on GitHub.

Patch to print traceback of python exceptions

Since python exceptions can occur for so many reasons in a complex setup, it's near impossible to track them down without a traceback. This patch simply hooks into the Ice exception catching to do a quick print to stderr before doing things normally.

I didn't add a config option because I'm not sure what sort of policies there are for choosing them (nor the best way to hook into it via the API). Something like Ice.Trace.UnknownExceptions=1 would be great to have for languages that can do it relatively easily (java and python that I know of).

(Diff generated against IcePy-2.1.2)

Comments

  • Ah, looks like those INCREFs aren't actually necessary (and causes a memory leak warning when you quit). Makes it even simpler without them:
    if( <config trace option> )
    {
       PyErr_Restore(t, val, tb);
       PyErr_Print();
    }
    
  • Mutter, okay, just got a seg fault that I cannot reproduce, so obviously one or more of the refs are needed (as I originally thought), but it's not obvious which. Ah well, I'll look again when I get some time.
  • After looking at the python source, it looks like the proper way to do this is:
    if( <print traceback> )
    {
            Py_XINCREF(t);
            Py_XINCREF(val);
            Py_XINCREF(tb);
            PyErr_Restore(t, val, tb);
            PyErr_PrintEx(0);
    }
    

    The difference is in the last call which tells it not to 'save' the current exception values when printing them, thus allowing the ref counts to clear normally. Been using this for better part of a day now with no trouble.
  • mes
    mes California
    Hi Chris,

    The next release will include a solution, but we're doing it a bit differently. If a server raises an unknown or invalid exception, the Ice run time returns Ice.UnknownException (or one of its derived types) to the client. This exception has a member named 'unknown' which can be used to provide additional information. IcePy will format the exception stack trace and include it in the 'unknown' member.

    If you define the property Ice.Warn.Dispatch=1, the Ice run time will display these unknown exceptions automatically (including the 'unknown' member). The stack trace information is also available to the client.

    Take care,
    - Mark
  • mes wrote:
    The next release will include a solution, but we're doing it a bit differently.

    That works too. Good stuff! It was/is darn hard to debug this stuff otherwise.