about summary refs log tree commit diff
path: root/lib/tests
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2022-06-14 23:12:46 +0200
committerRobert Hensing <robert@roberthensing.nl>2022-06-14 23:23:41 +0200
commit3c4a49f506575306f8b355e86d2b19cf02c84688 (patch)
treecfe4861a2dc0b4ac1b0a34af7569d1ecb7695f5a /lib/tests
parentdfd98a5da26c341cf3b7e6fe7e2dbbaeb0af519c (diff)
lib/modules: Throw earlier when module function does not return attrs
`m` must always be an attrset at this point. It is basically always
evaluated. This will make it throw when any of the attrs is accessed,
rather than just `config`. We assume that this will improve the error
message in more scenarios.
Diffstat (limited to 'lib/tests')
-rwxr-xr-xlib/tests/modules.sh1
-rw-r--r--lib/tests/modules/deferred-module-error.nix20
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index 29f6272ea50aa..c92cc62023b56 100755
--- a/lib/tests/modules.sh
+++ b/lib/tests/modules.sh
@@ -199,6 +199,7 @@ checkConfigOutput '^true$' config.submodule.enable ./declare-submoduleWith-path.
 checkConfigOutput '"beta"' config.nodes.foo.settingsDict.c ./deferred-module.nix
 # errors from the default module are reported with accurate location
 checkConfigError 'In `the-file-that-contains-the-bad-config.nix, via option default'\'': "bogus"' config.nodes.foo.bottom ./deferred-module.nix
+checkConfigError '.*lib/tests/modules/deferred-module-error.nix, via option deferred [(]:anon-1:anon-1:anon-1[)] does not look like a module.' config.result ./deferred-module-error.nix
 
 # Check the file location information is propagated into submodules
 checkConfigOutput the-file.nix config.submodule.internalFiles.0 ./submoduleFiles.nix
diff --git a/lib/tests/modules/deferred-module-error.nix b/lib/tests/modules/deferred-module-error.nix
new file mode 100644
index 0000000000000..d48ae092e8fe8
--- /dev/null
+++ b/lib/tests/modules/deferred-module-error.nix
@@ -0,0 +1,20 @@
+{ config, lib, ... }:
+let
+  inherit (lib) types mkOption setDefaultModuleLocation evalModules;
+  inherit (types) deferredModule lazyAttrsOf submodule str raw enum;
+in
+{
+  options = {
+    deferred = mkOption {
+      type = deferredModule;
+    };
+    result = mkOption {
+      default = (evalModules { modules = [ config.deferred ]; }).config.result;
+    };
+  };
+  config = {
+    deferred = { ... }:
+      # this should be an attrset, so this fails
+      true;
+  };
+}