Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: cms/sources.py

Issue 29600635: Noissue - Improve error reporting for broken locale files (Closed)
Patch Set: Created Nov. 7, 2017, 6:53 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cms/sources.py
===================================================================
--- a/cms/sources.py
+++ b/cms/sources.py
@@ -169,20 +169,28 @@
def read_locale(self, locale, page):
default_locale = self.read_config().get('general', 'defaultlocale')
result = collections.OrderedDict()
if locale != default_locale:
result.update(self.read_locale(default_locale, page))
if self.has_locale(locale, page):
- filedata = self.read_file(self.locale_filename(locale, page))[0]
- localedata = json.loads(filedata)
- for key, value in localedata.iteritems():
- result[key] = value['message']
+ filename = self.locale_filename(locale, page)
+ filedata, filepath = self.read_file(filename)
+ try:
+ localedata = json.loads(filedata)
+ for key, value in localedata.iteritems():
+ result[key] = value['message']
+ except (AttributeError, ValueError):
Vasily Kuznetsov 2017/11/07 18:57:35 ValueError if JSON parsing fails, AttributeError i
mathias 2017/11/07 20:13:30 What about the KeyError when 'message' is not in t
Vasily Kuznetsov 2017/11/27 18:35:23 That's a bit of a different error, but sure, let's
+ raise ValueError(
+ 'The content of translations file for page "{}", '
+ 'language "{}" ({}) is not a valid JSON dictionary'
+ .format(page, locale, filepath)
+ )
return result
#
# Template helpers
#
@staticmethod
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld