From 5fb20d2f8cad7a6332baafbb2986ac0ef16c6fc7 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sat, 10 Dec 2022 23:23:42 +0100 Subject: [PATCH 1/2] lib.modules: Add error context to rendered default and example attrs --- lib/options.nix | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/options.nix b/lib/options.nix index b13687576e81..0fd5b64a65d1 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -221,9 +221,10 @@ rec { 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; @@ -234,8 +235,18 @@ rec { 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 = From 1a44080088c3a4384da7e4529928f7a0a7b1aa4e Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sat, 10 Dec 2022 23:36:46 +0100 Subject: [PATCH 2/2] lib.generators.toPretty: Add attribute name to error context --- lib/generators.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/generators.nix b/lib/generators.nix index c0fe69389e00..4c9c2d1e9869 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -342,7 +342,10 @@ rec { 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 "";