Edgewall Software
Modify

Opened 6 years ago

Closed 6 years ago

#11780 closed defect (fixed)

UnicodeError with its traceback should be logged while rendering genshi template

Reported by: Jun Omae Owned by: Jun Omae
Priority: normal Milestone: 1.0.5
Component: rendering Version: 0.12-stable
Severity: normal Keywords: genshi
Cc: Branch:
Release Notes:

Add template name to error message if an exception is raised while rendering and location is unknown.

API Changes:
Internal Changes:

Description

If an UnicodeError raises while rendering genshi template, traceback of the error will not be logged. The behavior makes increasingly difficult to solve, especially if rendering unknown template location.

I think we should log the error with its traceback in this case.

  • trac/web/chrome.py

    diff --git a/trac/web/chrome.py b/trac/web/chrome.py
    index 344448b..fd14cbd 100644
    a b class Chrome(Component):  
    885885            req.chrome['script_data'] = script_data
    886886            # give some hints when hitting a Genshi unicode error
    887887            if isinstance(e, UnicodeError):
     888                self.log.error('Exception caught while rendering %s%s',
     889                               filename,
     890                               exception_to_unicode(e, traceback=True))
    888891                pos = self._stream_location(stream)
    889892                if pos:
    890893                    location = "'%s', line %s, char %s" % pos

Attachments (0)

Change History (5)

comment:1 by Jun Omae, 6 years ago

Milestone: 0.12.71.0.3
Owner: set to Jun Omae
Status: newassigned

comment:2 by Jun Omae, 6 years ago

Milestone: 1.0.31.0.4

comment:3 by Ryan J Ollos, 6 years ago

Milestone: 1.0.41.0.5

comment:4 by Jun Omae, 6 years ago

That is less-useful….

2015-02-21 18:15:16,332 Trac[chrome] ERROR: Genshi UnicodeDecodeError error while rendering template ticket.html
Traceback (most recent call last):
  File "/src/tracdev/git/trac/web/chrome.py", line 1096, in render_template
    encoding='utf-8')
  File "/venv/py25-1.0/lib/python2.5/site-packages/genshi/core.py", line 184, in render
  ...
  File "/venv/py25-1.0/lib/python2.5/site-packages/genshi/template/eval.py", line 178, in evaluate
  File "/src/tracdev/git/trac/ticket/templates/ticket_box.html", line 124, in <Expression u'wiki_to_html(context, ticket.description, escape_newlines=preserve_newlines)'>
    ${wiki_to_html(context, ticket.description, escape_newlines=preserve_newlines)}
  File "/src/tracdev/git/trac/wiki/formatter.py", line 1579, in format_to_html
    return HtmlFormatter(env, context, wikidom).generate(escape_newlines)
  File "/src/tracdev/git/trac/wiki/formatter.py", line 1534, in generate
    escape_newlines)
  File "/src/tracdev/git/trac/wiki/formatter.py", line 1316, in format
    result = re.sub(self.wikiparser.rules, self.replace, line)
  File "/home/jun66j5/venv/py25-1.0/lib/python2.5/re.py", line 150, in sub
    return _compile(pattern, 0).sub(repl, string, count)
  File "/src/tracdev/git/trac/wiki/formatter.py", line 1236, in replace
    return _markup_to_unicode(replacement)
  File "/src/tracdev/git/trac/wiki/formatter.py", line 109, in _markup_to_unicode
    markup = stream.render('xhtml', encoding=None, strip_whitespace=False)
  File "/venv/py25-1.0/lib/python2.5/site-packages/genshi/core.py", line 184, in render
  File "/venv/py25-1.0/lib/python2.5/site-packages/genshi/output.py", line 57, in encode
  File "/venv/py25-1.0/lib/python2.5/site-packages/genshi/output.py", line 387, in __call__
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 2999: ordinal not in range(128)
2015-02-21 18:15:16,332 Trac[main] WARNING: [192.168.11.13] HTTPInternalError: 500 Trac Error (Genshi UnicodeDecodeError error while rendering template (unknown template location))

Instead, it would be better to add the template filename to error message when (unknown template location).

  • trac/web/chrome.py

    diff --git a/trac/web/chrome.py b/trac/web/chrome.py
    index c4a5277..25c90c8 100644
    a b class Chrome(Component):  
    11071107                if pos:
    11081108                    location = "'%s', line %s, char %s" % pos
    11091109                else:
    1110                     location = _("(unknown template location)")
     1110                    location = '%s %s' % (filename,
     1111                                          _("(unknown template location)"))
    11111112                raise TracError(_("Genshi %(error)s error while rendering "
    11121113                                  "template %(location)s",
    11131114                                  error=e.__class__.__name__,
2015-02-21 22:23:56,696 Trac[main] WARNING: [192.168.11.13] HTTPInternalError: 500 Trac Error (Genshi UnicodeDecodeError error while rendering template ticket.html (unknown template location))

comment:5 by Jun Omae, 6 years ago

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

Committed the patch in comment:4 in [13779-13780].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae 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.