git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #95446 from Ma27/improve-opt-not-defined-error

lib/modules: improve error-message for undeclared options if prefix contains no options

commitf8962fd92ed4c1afeb6badbddc57002f53cc4a8f authorSilvan Mosberger <contact@infinisil.com> dateTue 18 Aug 2020, 18:26 (6 years ago) parent0a84375fa30c9a
1 file changed+13−2
lib/modules.nix+13−2
lib/modules.nix+13−2
@@ -115,8 +115,19 @@ rec {
115115
116116 checkUnmatched =
117117 if config._module.check && config._module.freeformType == null && merged.unmatchedDefns != [] then
118− let firstDef = head merged.unmatchedDefns;
119− in throw "The option `${showOption (prefix ++ firstDef.prefix)}' defined in `${firstDef.file}' does not exist."
118+ let
119+ firstDef = head merged.unmatchedDefns;
120+ baseMsg = "The option `${showOption (prefix ++ firstDef.prefix)}' defined in `${firstDef.file}' does not exist.";
121+ in
122+ if attrNames options == [ "_module" ]
123+ then throw ''
124+ ${baseMsg}
125+
126+ However there are no options defined in `${showOption prefix}'. Are you sure you've
127+ declared your options properly? This can happen if you e.g. declared your options in `types.submodule'
128+ under `config' rather than `options'.
129+ ''
130+ else throw baseMsg
120131 else null;
121132
122133 result = builtins.seq checkUnmatched {