Skip to content

Commit

Permalink
lib/modules: Report a better error when option tree has bare type
Browse files Browse the repository at this point in the history
Improves on 239f44b
- NixOS/nixpkgs#242339

We actually do have the file name.

Thanks Shawn8901 for the [feedback]!

feedback: NixOS/nixpkgs#242339 (comment)
  • Loading branch information
roberth committed Aug 18, 2023
1 parent d3a6938 commit e4dfb80
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ let
optionDecls = filter
(m: m.options?_type
&& (m.options._type == "option"
|| throwDeclarationTypeError loc m.options._type
|| throwDeclarationTypeError loc m.options._type m._file
)
)
decls;
Expand Down Expand Up @@ -698,14 +698,14 @@ let
) unmatchedDefnsByName);
};

throwDeclarationTypeError = loc: actualTag:
throwDeclarationTypeError = loc: actualTag: file:
let
name = lib.strings.escapeNixIdentifier (lib.lists.last loc);
path = showOption loc;
depth = length loc;

paragraphs = [
"Expected an option declaration at option path `${path}` but got an attribute set with type ${actualTag}"
"In module ${file}: expected an option declaration at option path `${path}` but got an attribute set with type ${actualTag}"
] ++ optional (actualTag == "option-type") ''
When declaring an option, you must wrap the type in a `mkOption` call. It should look somewhat like:
${comment}
Expand Down

0 comments on commit e4dfb80

Please sign in to comment.