Opened 17 years ago
Closed 16 years ago
#7303 closed defect (fixed)
trac-admin command fails with TracError includes non-ASCII chars
Reported by: | Owned by: | Christian Boos | |
---|---|---|---|
Priority: | normal | Milestone: | 0.11.1 |
Component: | admin/console | Version: | 0.11rc1 |
Severity: | normal | Keywords: | |
Cc: | trac-ja@… | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
When TracError
includes non-ASCII chars (i.e. Subversion's error message) at running trac-admin, command dumps stacktrace as UnicodeDecodeError.
This is a patch againsts Trac-0.11rc1:
-
trac/admin/console.py
106 106 raise 107 107 except TracError, e: 108 print>>sys.stderr, 'Command failed: %s' % to_unicode(e) 108 msg = u'Command failed: %s' % to_unicode(e) 109 msg = msg.encode(sys.stderr.encoding) 110 print>>sys.stderr, msg 109 111 rv = 2 110 112 if not self.interactive:
Attachments (1)
Change History (7)
follow-up: 2 comment:1 by , 17 years ago
comment:2 by , 17 years ago
comment:3 by , 17 years ago
Patch update:
-
trac/admin/console.py
old new 105 105 except SystemExit: 106 106 raise 107 107 except TracError, e: 108 print>>sys.stderr, 'Command failed: %s' % e 108 cons_charset = getattr(sys.stderr, 'encoding', None) or 'utf-8' 109 msg = 'Command failed: %s' % to_unicode(e) 110 print>>sys.stderr, msg.encode(cons_charset) 109 111 rv = 2 110 112 if not self.interactive: 111 113 return rv
comment:4 by , 17 years ago
It might be worth to have some additional utility function in trac.util.text
, e.g.
def console_print(out, *args): cons_charset = getattr(out, 'encoding', None) or 'utf-8' print>>out, *[to_unicode(a).encode(cons_charset) for a in args]
(untested)
What do you think?
by , 16 years ago
Attachment: | 7303-fix-print-to-console.patch added |
---|
Use console_print
helper instead of direct print, for converting the output to the console charset
comment:5 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
The 7303-fix-print-to-console.patch is a follow-up to the patches on #6677. You need those changes as soon as you have a failure involving an unicode path.
The unit-tests are all OK, but as the changes are quite pervasive I didn't test all the code paths and it would be good to get additional review/testing on this.
Replying to trac-ja@i-act.co.jp:
AFAICT, this patch is not valid: sys.stderr.encoding may be
None
, and would cause a fatal error on sane environment.Search the Trac DB, this kind of issue has already been addressed.