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

Delta Between Two Patch Sets: cms/sources.py

Issue 29600635: Noissue - Improve error reporting for broken locale files (Closed)
Left Patch Set: Created Nov. 7, 2017, 6:53 p.m.
Right Patch Set: Add handling of missing "message" key Created Nov. 27, 2017, 6:32 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 if locale != default_locale: 173 if locale != default_locale:
174 result.update(self.read_locale(default_locale, page)) 174 result.update(self.read_locale(default_locale, page))
175 175
176 if self.has_locale(locale, page): 176 if self.has_locale(locale, page):
177 filename = self.locale_filename(locale, page) 177 filename = self.locale_filename(locale, page)
178 filedata, filepath = self.read_file(filename) 178 filedata, filepath = self.read_file(filename)
179 try: 179 try:
180 localedata = json.loads(filedata) 180 localedata = json.loads(filedata)
181 for key, value in localedata.iteritems(): 181 for key, value in localedata.iteritems():
182 result[key] = value['message'] 182 result[key] = value['message']
183 except KeyError as ke:
184 if ke.message != 'message':
185 raise
186 raise ValueError(
187 'The content of translations file for page "{}", '
188 'language "{}" ({}) is not a valid translations file: '
189 '"message" key is missing for string: "{}"'
190 .format(page, locale, filepath, key)
191 )
183 except (AttributeError, ValueError): 192 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
184 raise ValueError( 193 raise ValueError(
185 'The content of translations file for page "{}", ' 194 'The content of translations file for page "{}", '
186 'language "{}" ({}) is not a valid JSON dictionary' 195 'language "{}" ({}) is not a valid JSON dictionary'
187 .format(page, locale, filepath) 196 .format(page, locale, filepath)
188 ) 197 )
189 198
190 return result 199 return result
191 200
192 # 201 #
193 # Template helpers 202 # Template helpers
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 'resolve_link', 451 'resolve_link',
443 'read_config', 452 'read_config',
444 'read_template', 453 'read_template',
445 'read_locale', 454 'read_locale',
446 'read_include', 455 'read_include',
447 'exec_file', 456 'exec_file',
448 ]: 457 ]:
449 setattr(source, fname, _memoize(getattr(source, fname))) 458 setattr(source, fname, _memoize(getattr(source, fname)))
450 459
451 return source 460 return source
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld