git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/doc/manual: print context on failing xmllint validation

Previously only the line numbers of a giant, internally generated XML file were printed, without any kind of debuggability. Now at least the mentioned lines are printed with a little bit of surrounding context (to have something to grep for). ``` manual-combined.xml:4863: element para: Relax-NG validity error : Did not expect element para there 4859 <chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-writing-modules"> 4860 4861 <title>Writing NixOS Modules</title> 4862 4863 <para>NixOS has a modular system for declarative configuration. This 4864 system combines multiple <emphasis>modules</emphasis> to produce the 4865 full system configuration. One of the modules that constitute the ```

commitf09f49d48344f6d6e4558da96c257c9567852273 authorProfpatsch <mail@profpatsch.de> dateSun 19 Nov 2017, 00:44 (9 years ago) parent7381a19
1 file changed+37−7
nixos/doc/manual/default.nix+37−7
nixos/doc/manual/default.nix+37−7
@@ -106,13 +106,43 @@ let
106106 xmllint --xinclude --noxincludenode \
107107 --output ./man-pages-combined.xml ./man-pages.xml
108108
109− xmllint --debug --noout --nonet \
110− --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \
111− manual-combined.xml
112− xmllint --debug --noout --nonet \
113− --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \
114− man-pages-combined.xml
115−
109+ # outputs the context of an xmllint error output
110+ # LEN lines around the failing line are printed
111+ function context {
112+ # length of context
113+ local LEN=6
114+ # lines to print before error line
115+ local BEFORE=4
116+
117+ # xmllint output lines are:
118+ # file.xml:1234: there was an error on line 1234
119+ while IFS=':' read -r file line rest; do
120+ echo
121+ if [[ -n "$rest" ]]; then
122+ echo "$file:$line:$rest"
123+ local FROM=$(($line>$BEFORE ? $line - $BEFORE : 1))
124+ # number lines & filter context
125+ nl --body-numbering=a "$file" | sed -n "$FROM,+$LEN p"
126+ else
127+ if [[ -n "$line" ]]; then
128+ echo "$file:$line"
129+ else
130+ echo "$file"
131+ fi
132+ fi
133+ done
134+ }
135+
136+ function lintrng {
137+ xmllint --debug --noout --nonet \
138+ --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \
139+ "$1" \
140+ 2>&1 | context 1>&2
141+ # ^ redirect assumes xmllint doesn’t print to stdout
142+ }
143+
144+ lintrng manual-combined.xml
145+ lintrng man-pages-combined.xml
116146
117147 mkdir $out
118148 cp manual-combined.xml $out/