Ticket #5920 (closed enhancement: invalid)
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
32 32 from trac.env import Environment 33 33 from trac.perm import PermissionSystem 34 34 from trac.ticket.model import * 35 from trac.util.compat import partial 35 36 from trac.util.datefmt import parse_date, format_date, format_datetime, utc 36 37 from trac.util.html import html 37 38 from trac.util.text import print_table, to_unicode, wrap … … 1132 1133 1133 1134 print 'Hotcopy done.' 1134 1135 1136 def 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 1146 for symbol in TracAdmin.__dict__.keys(): 1147 if symbol.startswith('do_'): 1148 setattr(TracAdmin, symbol, partial(backtrace_on_internal_errors, 1149 getattr(TracAdmin, symbol))) 1135 1150 1151 1136 1152 class TracAdminHelpMacro(WikiMacroBase): 1137 1153 """Displays help for trac-admin commands. 1138 1154
which works fine, but I wonder if there's a more elegant way to achieve this.
Opinions welcomed.
Attachments
Change History
Note: See
TracTickets for help on using
tickets.


