[openstack-dev] [oslo] Logging exceptions and Python 3
Joshua Harlow
harlowja at yahoo-inc.com
Fri May 16 15:00:29 UTC 2014
Another idea,
Django has the following: http://bit.ly/1n1cuWm
It seems like a useful similar function we can have to do the correct
thing for exceptions and other objects.
Or maybe we should talk with the django folks to see why they have a
useful method like that.
-Josh
-----Original Message-----
From: Victor Stinner <victor.stinner at enovance.com>
Organization: eNovance
Reply-To: "OpenStack Development Mailing List (not for usage questions)"
<openstack-dev at lists.openstack.org>
Date: Friday, May 16, 2014 at 7:04 AM
To: "OpenStack Development Mailing List (not for usage questions)"
<openstack-dev at lists.openstack.org>
Subject: Re: [openstack-dev] [oslo] Logging exceptions and Python 3
>Le vendredi 16 mai 2014, 06:03:53 Johannes Erdfelt a écrit :
>> On Fri, May 16, 2014, Igor Kalnitsky <ikalnitsky at mirantis.com> wrote:
>> > > According to http://legacy.python.org/dev/peps/pep-0352/ the message
>> > > attribute of BaseException is deprecated since Python 2.6 and was
>> > > dropped in Python 3.0.
>> >
>> > Some projects have custom exception hierarchy, with strictly defined
>> > attributes (e.g. message, or something else). In a previous mail, I
>> > mean exactly that case, not the case with a built-in exceptions.
>>
>> That's a fragile assumption to make.
>>
>> unicode(exc) (or six.text_type(exc)) works for all exceptions, built-in
>> or custom. I don't see the reason why it's being avoided.
>
>See my documentation:
>https://wiki.openstack.org/wiki/Python3#logging_module_and_format_exceptio
>ns
>
>" six.text_type(exc): always use Unicode. It may raise unicode error
>depending
>on the exception, be careful. Example of such error in python 2:
>unicode(Exception("nonascii:\xe9")). "
>
>unicode(exc) works with such exception classes:
>---
>class MyException1(Exception):
> pass
>
>exc = MyException1()
>exc.message = u"\u20ac"
>unicode(exc) #ok
>
>class MyException2(Exception):
> def __unicode__(self):
> return u"\20ac"
>
>exc = MyException2()
>unicode(exc) #ok
>---
>
>If we want to format an exception as Unicode, we need a function trying
>unicode(), or use str() and then guess the encoding. It means adding a
>new
>safe function to Olso to format an exception.
>
>Victor
>
>_______________________________________________
>OpenStack-dev mailing list
>OpenStack-dev at lists.openstack.org
>http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
More information about the OpenStack-dev
mailing list