[Windows] Logging breaks on unicode

Bug #540553 reported by Stani
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Phatch
Fix Released
High
Stani

Bug Description

Run the badge action on the tests/input/*.jpg file with this branch:
https://code.launchpad.net/~stani/phatch/logging_error

Important: this is an error during logging so it won't be logged and as such not registered by the test suite!

>python app.py
Traceback (most recent call last):
  File "C:\Python25\lib\logging\__init__.py", line 752, in emit
    self.stream.write(fs % msg.encode("UTF-8"))
  File "C:\Python25\lib\codecs.py", line 638, in write
    return self.writer.write(data)
  File "C:\Python25\lib\codecs.py", line 303, in write
    data, consumed = self.encode(object, self.errors)
  File "C:\Python25\lib\encodings\cp1252.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_table)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 133: ordina
l not in range(128)

Tags: windows

Related branches

Stani (stani)
summary: - Logging breaks on unicode
+ [Windows] Logging breaks on unicode
Stani (stani)
description: updated
Revision history for this message
Stani (stani) wrote :

This is probably not the best fix. So feel free to improve it. But at least now unicode filenames now can get logged and don't vanish from the test suite.

=== modified file 'phatch/core/api.py'
--- phatch/core/api.py 2010-03-18 03:51:30 +0000
+++ phatch/core/api.py 2010-03-18 04:50:22 +0000
@@ -145,13 +145,17 @@
         return
     if action:
         action = pprint.pformat(action.dump())
- details = WARN_MESSAGE % {
+ details = ensure_unicode(WARN_MESSAGE % {
         'number': WARNING_LOG_COUNTER + 1,
         'message': message,
         'input': input,
         'action': action,
- }
- logging.warn(details)
+ })
+ logging.warn(unicode(
+ details.encode(ENCODING,'replace'),
+ ENCODING,
+ 'replace'
+ ))
     WARNING_LOG_COUNTER += 1
     return details

@@ -177,15 +181,20 @@
     if exception:
         traceback_details = ensure_unicode(traceback.format_exc())
     else:
- traceback_details = ''
- details = ERROR_MESSAGE % {
+ traceback_details = ''
+ message = ensure_unicode(message)
+ details = ensure_unicode(ERROR_MESSAGE % {
         'number': ERROR_LOG_COUNTER + 1,
         'message': message,
         'input': input,
         'action': action,
         'details': traceback_details,
- }
- logging.error(details)
+ })
+ logging.error(unicode(
+ details.encode(ENCODING,'replace'),
+ ENCODING,
+ 'replace'
+ ))
     ERROR_LOG_COUNTER += 1
     if show:
         # keep this for last as in console mode phatch quits on an error

Changed in phatch:
assignee: Nadia Alramli (nadiana) → Stani (stani)
status: Confirmed → Fix Released
Revision history for this message
Stani (stani) wrote :
Stani (stani)
tags: added: windows
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.