Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3070 from fuglede/more-explicit-errors
Browse files Browse the repository at this point in the history
Changes to ruleset validation output
  • Loading branch information
semenko committed Dec 17, 2015
2 parents 3f3a19f + 286ad95 commit 3e8e703
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions utils/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,26 @@ fi
type xmllint >/dev/null || die "xmllint not available"

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

Expand Down

0 comments on commit 3e8e703

Please sign in to comment.