From f09f49d48344f6d6e4558da96c257c9567852273 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sun, 19 Nov 2017 00:44:17 +0100 Subject: [PATCH] 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 4860 4861 Writing NixOS Modules 4862 4863 NixOS has a modular system for declarative configuration. This 4864 system combines multiple modules to produce the 4865 full system configuration. One of the modules that constitute the ``` --- nixos/doc/manual/default.nix | 42 ++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/nixos/doc/manual/default.nix b/nixos/doc/manual/default.nix index 9413d71a34c..9bc83be6610 100644 --- a/nixos/doc/manual/default.nix +++ b/nixos/doc/manual/default.nix @@ -106,13 +106,43 @@ let xmllint --xinclude --noxincludenode \ --output ./man-pages-combined.xml ./man-pages.xml - xmllint --debug --noout --nonet \ - --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \ - manual-combined.xml - xmllint --debug --noout --nonet \ - --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \ - man-pages-combined.xml + # outputs the context of an xmllint error output + # LEN lines around the failing line are printed + function context { + # length of context + local LEN=6 + # lines to print before error line + local BEFORE=4 + # xmllint output lines are: + # file.xml:1234: there was an error on line 1234 + while IFS=':' read -r file line rest; do + echo + if [[ -n "$rest" ]]; then + echo "$file:$line:$rest" + local FROM=$(($line>$BEFORE ? $line - $BEFORE : 1)) + # number lines & filter context + nl --body-numbering=a "$file" | sed -n "$FROM,+$LEN p" + else + if [[ -n "$line" ]]; then + echo "$file:$line" + else + echo "$file" + fi + fi + done + } + + function lintrng { + xmllint --debug --noout --nonet \ + --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \ + "$1" \ + 2>&1 | context 1>&2 + # ^ redirect assumes xmllint doesn’t print to stdout + } + + lintrng manual-combined.xml + lintrng man-pages-combined.xml mkdir $out cp manual-combined.xml $out/