make error message nicer if type is ommitted

This commit is contained in:
Jörg Thalheim 2022-09-04 11:46:37 +02:00
parent dcb0c42857
commit e0de34c07d

View file

@ -10,7 +10,7 @@ rec {
subType = typeAttr: mkOptionType rec { subType = typeAttr: mkOptionType rec {
name = "subType"; name = "subType";
description = "one of ${attrNames typeAttr}"; description = "one of ${attrNames typeAttr}";
check = x: typeAttr.${x.type}.check x; check = x: if x ? type then typeAttr.${x.type}.check x else throw "No type option set in:\n${generators.toPretty {} x}";
merge = loc: defs: merge = loc: defs:
foldl' (res: def: typeAttr.${def.value.type}.merge loc [def]) {} defs; foldl' (res: def: typeAttr.${def.value.type}.merge loc [def]) {} defs;
nestedTypes = typeAttr; nestedTypes = typeAttr;
@ -780,6 +780,7 @@ rec {
type = mkOption { type = mkOption {
type = types.enum [ "zfs_dataset" ]; type = types.enum [ "zfs_dataset" ];
default = "zfs_dataset"; default = "zfs_dataset";
internal = true;
}; };
zfs_type = mkOption { zfs_type = mkOption {
type = types.enum [ "filesystem" "volume" ]; type = types.enum [ "filesystem" "volume" ];
@ -867,6 +868,7 @@ rec {
type = mkOption { type = mkOption {
type = types.enum [ "mdadm" ]; type = types.enum [ "mdadm" ];
default = "mdadm"; default = "mdadm";
internal = true;
}; };
level = mkOption { level = mkOption {
type = types.int; type = types.int;
@ -914,6 +916,7 @@ rec {
options = { options = {
type = mkOption { type = mkOption {
type = types.enum [ "mdraid" ]; type = types.enum [ "mdraid" ];
internal = true;
}; };
name = mkOption { name = mkOption {
@ -955,6 +958,7 @@ rec {
options = { options = {
type = mkOption { type = mkOption {
type = types.enum [ "luks" ]; type = types.enum [ "luks" ];
internal = true;
}; };
name = mkOption { name = mkOption {
type = types.str; type = types.str;