From ab8bf8c35beb13d6d3d1ac9cfe1ea30d29894e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Fri, 30 Aug 2024 11:31:26 +0200 Subject: [PATCH] lib/modules: improve error message when option is being accessed that isn't defined --- lib/modules.nix | 2 +- lib/tests/modules.sh | 8 ++++---- pkgs/tools/nix/nixos-option/src/nixos-option.cc | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/modules.nix b/lib/modules.nix index b9e9ca1e5d78a..c097f947cc4b3 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -861,7 +861,7 @@ let else # (nixos-option detects this specific error message and gives it special # handling. If changed here, please change it there too.) - throw "The option `${showOption loc}' is used but not defined."; + throw "The option `${showOption loc}' was accessed but has no value defined. Try setting the option."; isDefined = defsFinal != []; diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 3301a3d987ee8..68b1922940767 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -304,7 +304,7 @@ checkConfigOutput '^".*Hello.*"$' options.namedPackage.description ./declare-mkP checkConfigOutput '^"hello"$' config.pathPackage.pname ./declare-mkPackageOption.nix checkConfigOutput '^"pkgs\.hello\.override \{ stdenv = pkgs\.clangStdenv; \}"$' options.packageWithExample.example.text ./declare-mkPackageOption.nix checkConfigOutput '^".*Example extra description\..*"$' options.packageWithExtraDescription.description ./declare-mkPackageOption.nix -checkConfigError 'The option .undefinedPackage. is used but not defined' config.undefinedPackage ./declare-mkPackageOption.nix +checkConfigError 'The option .undefinedPackage. was accessed but has no value defined. Try setting the option.' config.undefinedPackage ./declare-mkPackageOption.nix checkConfigOutput '^null$' config.nullablePackage ./declare-mkPackageOption.nix checkConfigOutput '^"null or package"$' options.nullablePackageWithDefault.type.description ./declare-mkPackageOption.nix checkConfigOutput '^"myPkgs\.hello"$' options.packageWithPkgsText.defaultText.text ./declare-mkPackageOption.nix @@ -402,7 +402,7 @@ checkConfigOutput '^null$' config.foo ./freeform-attrsOf.nix ./freeform-str-dep- checkConfigOutput '^"24"$' config.foo ./freeform-attrsOf.nix ./freeform-str-dep-unstr.nix ./define-value-string.nix # Check whether an freeform-typed value can depend on a declared option, this can only work with lazyAttrsOf checkConfigError 'infinite recursion encountered' config.foo ./freeform-attrsOf.nix ./freeform-unstr-dep-str.nix -checkConfigError 'The option .* is used but not defined' config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix +checkConfigError 'The option .* was accessed but has no value defined. Try setting the option.' config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix checkConfigOutput '^"24"$' config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix ./define-value-string.nix # submodules in freeformTypes should have their locations annotated checkConfigOutput '/freeform-submodules.nix"$' config.fooDeclarations.0 ./freeform-submodules.nix @@ -461,8 +461,8 @@ checkConfigOutput "{}" config.attrs.a ./emptyValues.nix checkConfigOutput "null" config.null.a ./emptyValues.nix checkConfigOutput "{}" config.submodule.a ./emptyValues.nix # These types don't have empty values -checkConfigError 'The option .int.a. is used but not defined' config.int.a ./emptyValues.nix -checkConfigError 'The option .nonEmptyList.a. is used but not defined' config.nonEmptyList.a ./emptyValues.nix +checkConfigError 'The option .int.a. was accessed but has no value defined. Try setting the option.' config.int.a ./emptyValues.nix +checkConfigError 'The option .nonEmptyList.a. was accessed but has no value defined. Try setting the option.' config.nonEmptyList.a ./emptyValues.nix # types.unique # requires a single definition diff --git a/pkgs/tools/nix/nixos-option/src/nixos-option.cc b/pkgs/tools/nix/nixos-option/src/nixos-option.cc index eab727bc1db5a..658b836d491a8 100644 --- a/pkgs/tools/nix/nixos-option/src/nixos-option.cc +++ b/pkgs/tools/nix/nixos-option/src/nixos-option.cc @@ -465,7 +465,7 @@ void printValue(Context & ctx, Out & out, std::variant