templatefilters: raise ProgrammingError if unencodable type passed to json()
authorYuya Nishihara <yuya@tcha.org>
Sun, 18 Mar 2018 16:53:08 +0900
changeset 37230 63144f33c8bb
parent 37229 05db42732fce
child 37231 dc4bb1422f2b
templatefilters: raise ProgrammingError if unencodable type passed to json() This shouldn't happen for any template data types (though I know it does because of some templater bugs.) Let's clarify it is a bug.
mercurial/templatefilters.py
--- a/mercurial/templatefilters.py	Sun Mar 18 16:47:44 2018 +0900
+++ b/mercurial/templatefilters.py	Sun Mar 18 16:53:08 2018 +0900
@@ -263,8 +263,7 @@
     elif util.safehasattr(obj, '__iter__'):
         out = [json(i, paranoid) for i in obj]
         return '[' + ', '.join(out) + ']'
-    else:
-        raise TypeError('cannot encode type %s' % obj.__class__.__name__)
+    raise error.ProgrammingError('cannot encode %r' % obj)
 
 @templatefilter('lower', intype=bytes)
 def lower(text):