[Yum-devel] [PATCH 2/2] Convert YumBase exceptions from str(e) to exception2msg(e). BZ 669027.

Toshio Kuratomi a.badger at gmail.com
Wed Jan 12 18:14:19 UTC 2011


Note that there's a few places in this patch where you may start raising
a UnicodeException because before the code was either processing a str or
a unicode but your exception2msg() may return either a str or a unicode.

A kitchen-based exception2msg (either using something like I sent in reply
to Seth or copy and pasting code) would always return unicode or always
return bytes depending on how it was written (look at
kitchen.text.converters.exception_to_bytes if you want byte str instead of
unicode).  However, you still want to make sure that what you're feeding the
new exception to is prepared to accept the new format that you're giving it.

I'll give you a couple examples below:

On Wed, Jan 12, 2011 at 09:58:01AM -0500, James Antill wrote:
>              try:
>                  self._getTs(needTsRemove)
>              except yum.Errors.YumBaseError, e:
> -                return 1, [str(e)]
> +                return 1, [exception2msg(e)]
>  
The old code here would always return a byte str.  The new code may return
unicode.  If you get a unicode exception, it would probably be in code that
attempts to catch yum.Errors.YumBaseError.

>                  except yum.Errors.ConfigError, e:
> -                    self.logger.critical(e)
> +                    self.logger.critical(exception2msg(e))
>                      self.base.usage()
>                      sys.exit(1)
>  
I'm not quite sure how the logger handles conversion between unicode and str
internally.  You may get UnicodeErrors when using this if exception2msg() 
returns unicode type where the logger's internal handling was extracting the
message from the exception as a byte string (exercising different code
paths inside of the logger).

>          except yum.Errors.YumBaseError, e:
> -            return 1, [to_unicode(e)]
> +            return 1, [exception2msg(e)]
>
These could trigger UnicodeErrors if exception2msg returns a byte str
instead of unicode.  The exception would likely occur in code that attempts
to catch yum.Errors.YumBaseError.

-Toshio
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.baseurl.org/pipermail/yum-devel/attachments/20110112/ef482f6b/attachment-0001.asc>


More information about the Yum-devel mailing list