Skip to content

Commit 3e8e703

Browse files
committed
Merge pull request EFForg#3070 from fuglede/more-explicit-errors
Changes to ruleset validation output
2 parents 3f3a19f + 286ad95 commit 3e8e703

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

utils/validate.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,26 @@ fi
3333
type xmllint >/dev/null || die "xmllint not available"
3434

3535
GRAMMAR="relaxng.xml"
36-
# xmllint spams stderr with "<FILENAME> validates, even with the --noout
37-
# flag. We can't grep -v for that line, because the pipeline will mask error
38-
# status from xmllint. Instead we run it once going to /dev/null, and if
39-
# there's an error run it again, showing only error output.
36+
# xmllint spams stderr with "<FILENAME> validates, even with the --noout flag,
37+
# so we capture only the results that do not contain 'validates'
4038
validate_grammar() {
4139
find ../src/chrome/content/rules -name "*.xml" | \
4240
xargs xmllint --noout --relaxng $GRAMMAR
4341
}
44-
if validate_grammar 2>/dev/null
42+
grammar_errors=$(validate_grammar 2>&1 | grep -v "validates" || true)
43+
if [ -z "$grammar_errors" ]
4544
then
4645
echo Validation of rulesets against $GRAMMAR succeeded. >&2
4746
else
48-
validate_grammar 2>&1 | grep -v validates
47+
echo >&2 "$grammar_errors"
48+
# One very common error is to mess up rule attributes, so we check for
49+
# this explicitly.
50+
if [[ $grammar_errors == *"Element rule failed to validate attributes"* ]]
51+
then
52+
echo "Two very common reasons for this are the following:"
53+
echo "- Missing caret (^) in 'from' attribute: it should be \"^http:\" and not \"http:\"."
54+
echo "- Missing trailing slashes in 'from' or 'to' when specifying full hostnames: it should be \"https://eff.org/\" and not \"https://eff.org\"."
55+
fi
4956
die "Validation of rulesets against $GRAMMAR failed."
5057
fi
5158

0 commit comments

Comments
 (0)