Edgewall Software
Modify

Opened 16 years ago

Closed 16 years ago

#7303 closed defect (fixed)

trac-admin command fails with TracError includes non-ASCII chars

Reported by: trac-ja@… 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

     
    106106            raise
    107107        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
    109111            rv = 2
    110112        if not self.interactive:

Attachments (1)

7303-fix-print-to-console.patch (7.0 KB ) - added by Christian Boos 16 years ago.
Use console_print helper instead of direct print, for converting the output to the console charset

Download all attachments as: .zip

Change History (7)

in reply to:  description ; comment:1 by Emmanuel Blot, 16 years ago

Replying to trac-ja@i-act.co.jp:

When TracError includes non-ASCII chars (i.e. Subversion's error message) at running trac-admin, command dumps stacktrace as UnicodeDecodeError.

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.

in reply to:  1 comment:2 by Emmanuel Blot, 16 years ago

Replying to eblot:

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.

See #4742

comment:3 by trac-ja@…, 16 years ago

Patch update:

  • trac/admin/console.py

    old new  
    105105        except SystemExit:
    106106            raise
    107107        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)
    109111            rv = 2
    110112        if not self.interactive:
    111113            return rv

comment:4 by Christian Boos, 16 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 Christian Boos, 16 years ago

Use console_print helper instead of direct print, for converting the output to the console charset

comment:5 by Christian Boos, 16 years ago

Owner: changed from Christopher Lenz to Christian Boos
Status: newassigned

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.

comment:6 by Christian Boos, 16 years ago

Resolution: fixed
Status: assignedclosed

Patch applied in r7362.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.