mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-17 19:21:04 +00:00
lib/modules: improve error message when option is being accessed that isn't defined
This commit is contained in:
parent
5babc04681
commit
ab8bf8c35b
|
@ -861,7 +861,7 @@ let
|
||||||
else
|
else
|
||||||
# (nixos-option detects this specific error message and gives it special
|
# (nixos-option detects this specific error message and gives it special
|
||||||
# handling. If changed here, please change it there too.)
|
# 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 != [];
|
isDefined = defsFinal != [];
|
||||||
|
|
||||||
|
|
|
@ -304,7 +304,7 @@ checkConfigOutput '^".*Hello.*"$' options.namedPackage.description ./declare-mkP
|
||||||
checkConfigOutput '^"hello"$' config.pathPackage.pname ./declare-mkPackageOption.nix
|
checkConfigOutput '^"hello"$' config.pathPackage.pname ./declare-mkPackageOption.nix
|
||||||
checkConfigOutput '^"pkgs\.hello\.override \{ stdenv = pkgs\.clangStdenv; \}"$' options.packageWithExample.example.text ./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
|
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$' config.nullablePackage ./declare-mkPackageOption.nix
|
||||||
checkConfigOutput '^"null or package"$' options.nullablePackageWithDefault.type.description ./declare-mkPackageOption.nix
|
checkConfigOutput '^"null or package"$' options.nullablePackageWithDefault.type.description ./declare-mkPackageOption.nix
|
||||||
checkConfigOutput '^"myPkgs\.hello"$' options.packageWithPkgsText.defaultText.text ./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
|
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
|
# 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 '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
|
checkConfigOutput '^"24"$' config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix ./define-value-string.nix
|
||||||
# submodules in freeformTypes should have their locations annotated
|
# submodules in freeformTypes should have their locations annotated
|
||||||
checkConfigOutput '/freeform-submodules.nix"$' config.fooDeclarations.0 ./freeform-submodules.nix
|
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 "null" config.null.a ./emptyValues.nix
|
||||||
checkConfigOutput "{}" config.submodule.a ./emptyValues.nix
|
checkConfigOutput "{}" config.submodule.a ./emptyValues.nix
|
||||||
# These types don't have empty values
|
# 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 .int.a. was accessed but has no value defined. Try setting the option.' config.int.a ./emptyValues.nix
|
||||||
checkConfigError 'The option .nonEmptyList.a. is used but not defined' config.nonEmptyList.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
|
# types.unique
|
||||||
# requires a single definition
|
# requires a single definition
|
||||||
|
|
|
@ -465,7 +465,7 @@ void printValue(Context & ctx, Out & out, std::variant<Value, std::exception_ptr
|
||||||
v.print(ctx.state.symbols, out.ostream);
|
v.print(ctx.state.symbols, out.ostream);
|
||||||
}
|
}
|
||||||
} catch (ThrownError & e) {
|
} catch (ThrownError & e) {
|
||||||
if (e.msg() == "The option `" + path + "' is used but not defined.") {
|
if (e.msg() == "The option `" + path + "' was accessed but has no value defined. Try setting the option.") {
|
||||||
// 93% of errors are this, and just letting this message through would be
|
// 93% of errors are this, and just letting this message through would be
|
||||||
// misleading. These values may or may not actually be "used" in the
|
// misleading. These values may or may not actually be "used" in the
|
||||||
// config. The thing throwing the error message assumes that if anything
|
// config. The thing throwing the error message assumes that if anything
|
||||||
|
|
Loading…
Reference in a new issue