diffviewer: better error message when repository encoding is wrong

Review Request #698 — Created Jan. 14, 2009 and submitted

Information

Review Board SVN (deprecated)

Reviewers

When the repository's encoding is misconfigured (e.g. I had UTF-8 configured explicitly and so ISO-8859-15 fallback wasn't used), the resulting error from diffutils.convert_to_utf8() is confusing:


local variable 'u' referenced before assignment

Traceback (most recent call last):
  File "/srv/reviewboard/py/reviewboard/diffviewer/views.py", line 82, in view_diff
    files = get_diff_files(diffset, None, interdiffset, highlighting)
  File "/srv/reviewboard/py/reviewboard/diffviewer/diffutils.py", line 599, in get_diff_files
    enable_syntax_highlighting)
  File "/srv/reviewboard/py/reviewboard/diffviewer/diffutils.py", line 518, in generate_files
    lambda: get_chunks(filediff.diffset,
  File "/srv/reviewboard/py/djblets/util/misc.py", line 49, in cache_memoize
    data = lookup_callable()
  File "/srv/reviewboard/py/reviewboard/diffviewer/diffutils.py", line 521, in <lambda>
    enable_syntax_highlighting))
  File "/srv/reviewboard/py/reviewboard/diffviewer/diffutils.py", line 335, in get_chunks
    old = convert_to_utf8(old, encoding)
  File "/srv/reviewboard/py/reviewboard/diffviewer/diffutils.py", line 198, in convert_to_utf8
    return u.encode('utf-8')
UnboundLocalError: local variable 'u' referenced before assignment


It wasn't until I debugged the code that I realized it's a configuration problem. This patch adds a more understandable error message.

 
chipx86
  1. Thanks! Committed as r1675.
  2.