Edgewall Software
Modify

Opened 17 years ago

Closed 17 years ago

#5920 closed enhancement (invalid)

trac-admin should show the backtrace for internal errors

Reported by: Christian Boos Owned by: Christian Boos
Priority: normal Milestone:
Component: admin/console Version:
Severity: normal Keywords: review
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

We already added some traceback.print_exc() for some commands, but I think this would be useful for all commands. The problem is that Cmd.cmdloop() catches all exceptions, so we'd need to do that for each do_... method. Then we still want to be compatible with Python 2.3, so we can't use decorators for that.

I came up with this:

  • trac/admin/console.py

     
    3232from trac.env import Environment
    3333from trac.perm import PermissionSystem
    3434from trac.ticket.model import *
     35from trac.util.compat import partial
    3536from trac.util.datefmt import parse_date, format_date, format_datetime, utc
    3637from trac.util.html import html
    3738from trac.util.text import print_table, to_unicode, wrap
     
    11321133
    11331134        print 'Hotcopy done.'
    11341135
     1136def backtrace_on_internal_errors(meth, self, *args, **kwargs):
     1137    try:
     1138        meth(self, *args, **kwargs)
     1139    except TracError, e:
     1140        raise
     1141    except Exception, e:
     1142        print 'Internal error: ', e
     1143        traceback.print_exc()
     1144        sys.exit(1)
     1145       
     1146for symbol in TracAdmin.__dict__.keys():
     1147    if symbol.startswith('do_'):
     1148        setattr(TracAdmin, symbol, partial(backtrace_on_internal_errors,
     1149                                           getattr(TracAdmin, symbol)))
    11351150
     1151
    11361152class TracAdminHelpMacro(WikiMacroBase):
    11371153    """Displays help for trac-admin commands.
    11381154

which works fine, but I wonder if there's a more elegant way to achieve this.

Opinions welcomed.

Attachments (0)

Change History (3)

comment:1 by Christian Boos, 17 years ago

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

comment:2 by ThurnerRupert, 17 years ago

more elegant than 5 lines of code? i don't know :)

comment:3 by Christian Boos, 17 years ago

Milestone: 0.11
Resolution: invalid
Status: assignedclosed

Well, I simply overlooked that we were catching all the exceptions, in onecmd

See r5962.

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.