|
33 | 33 | type xmllint >/dev/null || die "xmllint not available" |
34 | 34 |
|
35 | 35 | 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' |
40 | 38 | validate_grammar() { |
41 | 39 | find ../src/chrome/content/rules -name "*.xml" | \ |
42 | 40 | xargs xmllint --noout --relaxng $GRAMMAR |
43 | 41 | } |
44 | | -if validate_grammar 2>/dev/null |
| 42 | +grammar_errors=$(validate_grammar 2>&1 | grep -v "validates" || true) |
| 43 | +if [ -z "$grammar_errors" ] |
45 | 44 | then |
46 | 45 | echo Validation of rulesets against $GRAMMAR succeeded. >&2 |
47 | 46 | 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 |
49 | 56 | die "Validation of rulesets against $GRAMMAR failed." |
50 | 57 | fi |
51 | 58 |
|
|
0 commit comments