summary refs log tree commit diff
path: root/nixos/doc/manual/default.nix
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2017-11-19 00:44:17 +0100
committerProfpatsch <mail@profpatsch.de>2017-11-22 21:27:05 +0100
commitf09f49d48344f6d6e4558da96c257c9567852273 (patch)
tree8cb5ff413fe04ddeff49a08fe829471594433c1b /nixos/doc/manual/default.nix
parent7381a197f4ffdadc886468040d672065ce663567 (diff)
downloadnixpkgs-f09f49d48344f6d6e4558da96c257c9567852273.tar
nixpkgs-f09f49d48344f6d6e4558da96c257c9567852273.tar.gz
nixpkgs-f09f49d48344f6d6e4558da96c257c9567852273.tar.bz2
nixpkgs-f09f49d48344f6d6e4558da96c257c9567852273.tar.lz
nixpkgs-f09f49d48344f6d6e4558da96c257c9567852273.tar.xz
nixpkgs-f09f49d48344f6d6e4558da96c257c9567852273.tar.zst
nixpkgs-f09f49d48344f6d6e4558da96c257c9567852273.zip
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
```
Diffstat (limited to 'nixos/doc/manual/default.nix')
-rw-r--r--nixos/doc/manual/default.nix44
1 files changed, 37 insertions, 7 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/