Skip to content

Commit

Permalink
lib/modules: Throw better error when definitions assign to an option set
Browse files Browse the repository at this point in the history
  • Loading branch information
infinisil committed Mar 18, 2020
1 parent dcdd232 commit 15c873b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ rec {
in
throw "The option `${showOption loc}' in `${firstOption._file}' is a prefix of options in `${firstNonOption._file}'."
else
mergeModules' loc decls defns
if all (def: isAttrs def.value) defns' then mergeModules' loc decls defns
else let firstInvalid = findFirst (def: ! isAttrs def.value) null defns';
in throw "The option path `${showOption loc}' is an attribute set of options, but it is defined to not be an attribute set in `${firstInvalid.file}'. Did you define its value at the correct and complete path?"
))
// { _definedNames = map (m: { inherit (m) file; names = attrNames m.config; }) configs; };

Expand Down
4 changes: 4 additions & 0 deletions lib/tests/modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ checkConfigOutput "true" config.conditionalWorks ./declare-attrsOf.nix ./attrsOf
checkConfigOutput "false" config.conditionalWorks ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix
checkConfigOutput "empty" config.value.foo ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix

# Check error for when an option set is defined to be a non-attribute set value
checkConfigError 'The option path .* is an attribute set of options, but it is defined to not be an attribute set in' \
config.value ./declare-option-set.nix ./define-value-int-zero.nix

cat <<EOF
====== module tests ======
$pass Pass
Expand Down
3 changes: 3 additions & 0 deletions lib/tests/modules/declare-option-set.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
options.value = {};
}

0 comments on commit 15c873b

Please sign in to comment.