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: Add handling of missing "message" key Created Nov. 27, 2017, 6:32 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,37 @@
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 KeyError as ke:
+ if ke.message != 'message':
+ raise
+ raise ValueError(
+ 'The content of translations file for page "{}", '
+ 'language "{}" ({}) is not a valid translations file: '
+ '"message" key is missing for string: "{}"'
+ .format(page, locale, filepath, key)
+ )
+ except (AttributeError, ValueError):
+ 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