Commit 0ce17ce5 authored by Chris Sharp's avatar Chris Sharp Committed by Commit Bot

Provide clearer error messages when missing tags in policy_templates.json

Change-Id: I2e8e6b066fee60218dcc8de247ea79a80318b842
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2252741
Commit-Queue: Chris Sharp <csharp@chromium.org>
Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780361}
parent ad767dd8
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
import sys import sys
from xml.dom import minidom from xml.dom import minidom
from xml.parsers import expat
def _GetPolicyTemplates(template_path): def _GetPolicyTemplates(template_path):
# Read list of policies in the template. eval() is used instead of a JSON # Read list of policies in the template. eval() is used instead of a JSON
...@@ -205,7 +206,16 @@ def _CheckMissingPlaceholders(input_api, output_api, template_path): ...@@ -205,7 +206,16 @@ def _CheckMissingPlaceholders(input_api, output_api, template_path):
for key in ['desc', 'text']: for key in ['desc', 'text']:
if not key in item: if not key in item:
continue continue
node = minidom.parseString('<msg>%s</msg>' % item[key]).childNodes[0] try:
node = minidom.parseString('<msg>%s</msg>' % item[key]).childNodes[0]
except expat.ExpatError as e:
error = (
'Error when checking for missing placeholders: %s in:\n'
'!<Policy Start>!\n%s\n<Policy End>!' %
(e, item[key]))
results.append(output_api.PresubmitError(error))
continue
for child in node.childNodes: for child in node.childNodes:
if child.nodeType == minidom.Node.TEXT_NODE and '$' in child.data: if child.nodeType == minidom.Node.TEXT_NODE and '$' in child.data:
warning = ('Character \'$\' found outside of a placeholder in "%s". ' warning = ('Character \'$\' found outside of a placeholder in "%s". '
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment