Edgewall Software

Opened 8 years ago

Closed 8 years ago

Last modified 6 years ago

#12359 closed defect (fixed)

TracError: Unknown trac-admin command "copystatic" — at Version 4

Reported by: Ryan J Ollos Owned by: Ryan J Ollos
Priority: normal Milestone: 1.0.11
Component: admin/web Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Unknown trac-admin command error is trapped in TracAdminHelp macro and a system message is rendered.

API Changes:

Added MacroError exception, which is trapped when rendering the macro and the exception message is rendered as a system message.

Internal Changes:

Description

From the logs:

[pid 23657 140015545095936] 2016-02-16 02:44:34,470 Trac[formatter] ERROR: Macro TracAdminHelp(copystatic) failed:
Traceback (most recent call last):
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/trac/wiki/formatter.py", line 798, in _macro_formatter
    return macro.ensure_inline(macro.process(args))
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/trac/wiki/formatter.py", line 375, in process
    text = self.processor(text)
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/trac/wiki/formatter.py", line 347, in _macro_processor
    text)
  File "/usr/local/virtualenv/1.1dev/lib/python2.7/site-packages/trac/admin/console.py", line 588, in expand_macro
    command=content))
TracError: Unknown trac-admin command "copystatic"

Previously there was a copystatic command: [6894].

Change History (4)

comment:1 by Ryan J Ollos, 8 years ago

Proposed change is to return a system_message rather than raising a TracError:

  • trac/admin/console.py

    diff --git a/trac/admin/console.py b/trac/admin/console.py
    index 8385c80..4a7a753 100755
    a b from trac.util.translation import _, ngettext, has_babel, cleandoc_  
    3737from trac.versioncontrol.api import RepositoryManager
    3838from trac.wiki.admin import WikiAdmin
    3939from trac.wiki.macros import WikiMacroBase
     40from trac.wiki.formatter import system_message
    4041
    4142
    4243TRAC_VERSION = pkg_resources.get_distribution('Trac').version
    class TracAdminHelpMacro(WikiMacroBase):  
    550551                cmd_mgr = AdminCommandManager(self.env)
    551552                doc = cmd_mgr.get_command_help(arg)
    552553            if not doc:
    553                 raise TracError(_('Unknown trac-admin command "%(command)s"',
    554                                   command=content))
     554                return system_message(_('Unknown trac-admin command '
     555                                        '"%(command)s"', command=content))
    555556        else:
    556557            doc = TracAdmin.all_docs(self.env)
    557558        buf = StringIO.StringIO()
  • trac/admin/tests/console.py

    diff --git a/trac/admin/tests/console.py b/trac/admin/tests/console.py
    index 93227d6..5c60040 100644
    a b class TracAdminHelpMacroTestCase(unittest.TestCase):  
    13991399        help = unicode(macro.expand_macro(None, None, 'unicode-help'))
    14001400        self.assertTrue(unicode_help in help)
    14011401
     1402    def test_invalid_command(self):
     1403        macro = TracAdminHelpMacro(self.env)
     1404
     1405        help = unicode(macro.expand_macro(None, None, 'copystatic'))
     1406        self.assertIn('Unknown trac-admin command "copystatic"', help)
     1407
     1408
    14021409
    14031410def suite():
    14041411    suite = unittest.TestSuite()

comment:2 by Jun Omae, 8 years ago

Another solution is that expand_macro() raises ProcessorError (or new MacroError exception) for incorrect arguments, etc. and Formatter renders the exception as system_message.

  • trac/admin/console.py

    diff --git a/trac/admin/console.py b/trac/admin/console.py
    index 8385c806f..2e64fbff3 100755
    a b from trac.util.text import console_print, exception_to_unicode, printout, \  
    3636from trac.util.translation import _, ngettext, has_babel, cleandoc_
    3737from trac.versioncontrol.api import RepositoryManager
    3838from trac.wiki.admin import WikiAdmin
     39from trac.wiki.formatter import ProcessorError
    3940from trac.wiki.macros import WikiMacroBase
    4041
    4142
    class TracAdminHelpMacro(WikiMacroBase):  
    550551                cmd_mgr = AdminCommandManager(self.env)
    551552                doc = cmd_mgr.get_command_help(arg)
    552553            if not doc:
    553                 raise TracError(_('Unknown trac-admin command "%(command)s"',
    554                                   command=content))
     554                raise ProcessorError(_('Unknown trac-admin command '
     555                                       '"%(command)s"', command=content))
    555556        else:
    556557            doc = TracAdmin.all_docs(self.env)
    557558        buf = StringIO.StringIO()
  • trac/admin/tests/console.py

    diff --git a/trac/admin/tests/console.py b/trac/admin/tests/console.py
    index 93227d6d0..18c6f7602 100644
    a b from trac.util.datefmt import format_date, get_date_format_hint, \  
    5353                              get_datetime_format_hint
    5454from trac.util.translation import get_available_locales, has_babel
    5555from trac.web.tests.session import _prep_session_table
     56from trac.wiki.formatter import ProcessorError
    5657
    5758STRIP_TRAILING_SPACE = re.compile(r'( +)$', re.MULTILINE)
    5859
    class TracAdminHelpMacroTestCase(unittest.TestCase):  
    13991400        help = unicode(macro.expand_macro(None, None, 'unicode-help'))
    14001401        self.assertTrue(unicode_help in help)
    14011402
     1403    def test_invalid_command(self):
     1404        macro = TracAdminHelpMacro(self.env)
     1405        try:
     1406            macro.expand_macro(None, None, 'copystatic')
     1407            self.fail('ProcessorError not raised')
     1408        except ProcessorError, e:
     1409            self.assertEqual('Unknown trac-admin command "copystatic"',
     1410                             unicode(e))
     1411
    14021412
    14031413def suite():
    14041414    suite = unittest.TestSuite()
  • trac/wiki/formatter.py

    diff --git a/trac/wiki/formatter.py b/trac/wiki/formatter.py
    index 969074947..360f05612 100644
    a b class Formatter(object):  
    787787            args = fullmatch.group('macroargs')
    788788        try:
    789789            return macro.ensure_inline(macro.process(args))
     790        except ProcessorError, e:
     791            return system_message(e)
    790792        except Exception, e:
    791793            self.env.log.error('Macro %s(%s) failed:%s', name, args,
    792794                               exception_to_unicode(e, traceback=True))

comment:3 by Ryan J Ollos, 8 years ago

Owner: set to Ryan J Ollos
Status: newassigned

Thanks, I didn't know about ProcessorError. I'll push your changes.

comment:4 by Ryan J Ollos, 8 years ago

API Changes: modified (diff)
Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Committed to 1.0-stable in [14563], merged to trunk in [14564]. MacroError documented in TracDev/Exceptions@14.

Note: See TracTickets for help on using tickets.