lib.modules: Add prefix to imports type check error
This commit is contained in:
parent
ce0c6e269d
commit
38bb05d169
@ -389,6 +389,7 @@ let
|
||||
value = m;
|
||||
_type = m._type;
|
||||
expectedClass = class;
|
||||
prefix = args._prefix;
|
||||
}
|
||||
)
|
||||
else if isList m then
|
||||
@ -1977,6 +1978,10 @@ let
|
||||
file != null && file != unknownModule
|
||||
) ", while trying to load a module into ${toString file}";
|
||||
|
||||
into_prefix_maybe =
|
||||
prefix:
|
||||
optionalString (prefix != [ ]) ", while trying to load a module into ${code (showOption prefix)}";
|
||||
|
||||
/**
|
||||
Format text with one line break between each list item.
|
||||
*/
|
||||
@ -2029,7 +2034,7 @@ let
|
||||
paragraphs (
|
||||
[
|
||||
''
|
||||
Expected a module, but found a value of type ${warn (escapeNixString _type)}${into_fallback_file_maybe fallbackFile}.
|
||||
Expected a module, but found a value of type ${warn (escapeNixString _type)}${into_fallback_file_maybe fallbackFile}${into_prefix_maybe prefix}.
|
||||
A module is typically loaded by adding it to the ${code "imports = [ ... ];"} attribute of an existing module, or in the ${code "modules = [ ... ];"} argument of various functions.
|
||||
Please make sure that each of the list items is a module, and not a different kind of value.
|
||||
''
|
||||
|
@ -606,6 +606,7 @@ checkConfigError 'Expected a module, but found a value of type .*"flake".*, whil
|
||||
checkConfigOutput '^true$' config.enable ./declare-enable.nix ./define-enable-with-top-level-mkIf.nix
|
||||
checkConfigError 'Expected a module, but found a value of type .*"configuration".*, while trying to load a module into .*/import-configuration.nix.' config ./import-configuration.nix
|
||||
checkConfigError 'please only import the modules that make up the configuration' config ./import-configuration.nix
|
||||
checkConfigError 'Expected a module, but found a value of type "configuration", while trying to load a module into .*/import-error-submodule.nix, while trying to load a module into .*foo.*\.' config.foo ./import-error-submodule.nix
|
||||
|
||||
# doRename works when `warnings` does not exist.
|
||||
checkConfigOutput '^1234$' config.c.d.e ./doRename-basic.nix
|
||||
|
18
lib/tests/modules/import-error-submodule.nix
Normal file
18
lib/tests/modules/import-error-submodule.nix
Normal file
@ -0,0 +1,18 @@
|
||||
{ lib, ... }:
|
||||
let
|
||||
myconf = lib.evalModules { modules = [ { } ]; };
|
||||
in
|
||||
{
|
||||
options.foo = lib.mkOption {
|
||||
type = lib.types.submodule { };
|
||||
default = { };
|
||||
};
|
||||
config.foo =
|
||||
{ ... }:
|
||||
{
|
||||
imports = [
|
||||
# error, like `import-configuration.nix`, but in a submodule this time
|
||||
myconf
|
||||
];
|
||||
};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user