Comment 1 for bug 1499727

Revision history for this message
Yuriy Taraday (yorik-sar) wrote :

Here's what leads to this problem:

- some IOError happens;
- IOError gets string associated with errno value based on current locale (which just happend to be ru_RU.UTF-8), gets UTF-8-encoded str object;
- cliff catches this IOError in "err" variable and does "log.error(err)";
- some dozen layers down we end up in StreamHandler.emit method;
- it calls "formatter.format(msg)" (msg is still IOError here) and gets that str object;
- seeing that it's not a unicode, emit() then does "'%s\n' % msg" which succeeds in adding a newline to the string;
- then it passes it to stream.write();
- stream has 'UTF-8' encoding set, so first thing it does is "self.encode(object, self.errors)" which expects object to be a unicode string, but it's not, so it tries implicitly convert it with ASCII encdoding and blows up;
- emit() has nothing better to do but to try "msg.encode('utf-8')" in exception handler, which obviously blows up as well;
- we have new bug in Launchpad.

We should probably convert all messages passed to emit() to Unicode with UTF-8 encoding (or current system encoding) ourselves.