Edgewall Software

Ticket #5920 (closed enhancement: invalid)

Opened 15 months ago

Last modified 15 months ago

trac-admin should show the backtrace for internal errors

Reported by: cboos Owned by: cboos
Priority: normal Milestone:
Component: admin/console Version:
Severity: normal Keywords: review
Cc:

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

Change History

Changed 15 months ago by cboos

  • owner changed from cmlenz to cboos
  • status changed from new to assigned

Changed 15 months ago by ThurnerRupert

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

Changed 15 months ago by cboos

  • status changed from assigned to closed
  • resolution set to invalid
  • milestone 0.11 deleted

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

See r5962.

Add/Change #5920 (trac-admin should show the backtrace for internal errors)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
to The owner will change from cboos. Next status will be 'closed'
 
Note: See TracTickets for help on using tickets.