Merge pull request #205563 from hercules-ci/lib-modules-doc-default-and-example-error-context

lib.modules: Add error context to rendered default and example attrs

Changed files
+18 -4
lib
+4 -1
lib/generators.nix
···
else "{" + introSpace
+ libStr.concatStringsSep introSpace (libAttr.mapAttrsToList
(name: value:
-
"${libStr.escapeNixIdentifier name} = ${go (indent + " ") value};") v)
+
"${libStr.escapeNixIdentifier name} = ${
+
builtins.addErrorContext "while evaluating an attribute `${name}`"
+
(go (indent + " ") value)
+
};") v)
+ outroSpace + "}"
else abort "generators.toPretty: should never happen (v = ${v})";
in go "";
+14 -3
lib/options.nix
···
optionAttrSetToDocList' = _: options:
concatMap (opt:
let
+
name = showOption opt.loc;
docOption = rec {
loc = opt.loc;
-
name = showOption opt.loc;
+
inherit name;
description = opt.description or null;
declarations = filter (x: x != unknownModule) opt.declarations;
internal = opt.internal or false;
···
readOnly = opt.readOnly or false;
type = opt.type.description or "unspecified";
}
-
// optionalAttrs (opt ? example) { example = renderOptionValue opt.example; }
-
// optionalAttrs (opt ? default) { default = renderOptionValue (opt.defaultText or opt.default); }
+
// optionalAttrs (opt ? example) {
+
example =
+
builtins.addErrorContext "while evaluating the example of option `${name}`" (
+
renderOptionValue opt.example
+
);
+
}
+
// optionalAttrs (opt ? default) {
+
default =
+
builtins.addErrorContext "while evaluating the default value of option `${name}`" (
+
renderOptionValue (opt.defaultText or opt.default)
+
);
+
}
// optionalAttrs (opt ? relatedPackages && opt.relatedPackages != null) { inherit (opt) relatedPackages; };
subOptions =