GNOME Bugzilla – Bug 606224
Exceptions do not return unicode data
Last modified: 2010-02-05 02:51:09 UTC
I was having a problem passing a unicode string to LdtpExecutionError: import ldtp try: raise ldtp.LdtpExecutionError(u"testraise\u221a") except Exception, e: print unicode(e) The exceptions in LDTP seem to be copied from examples in the Python documentation for overriding exceptions. Resultantly, they store the message in a variable called value rather than in the args variable like the base class. This wouldn't be a problem except that the base class has its own __unicode__ method which depends on the args variable, so calling unicode() on an LDTP exception returns a null string. Changing exceptions to just use the Exception class as-is resolves this issue. The attached patch also makes LDTP exceptions inherit from ldtp.Error so all LDTP exceptions can be caught by catching ldtp.Error. I think this was the original design philosophy but it wasn't implemented. There were quite a few places where an exception handler used LdtpExecutionError.value - these are updated in the 0002 patch.
Created attachment 150907 [details] [review] Update exceptions to use standard base exception class
Created attachment 150908 [details] [review] Update exception handlers that use .value to use str()
James, Thanks for the bug report and patch. Its fixed in git.
Review of attachment 150907 [details] [review]: Thanks for the patch
Review of attachment 150908 [details] [review]: Thanks for the patch