lib.types.attrTag: Custom error when passing bare type
This commit is contained in:
parent
bcd774606a
commit
1465777b63
3 changed files with 23 additions and 1 deletions
|
@ -113,6 +113,7 @@ checkConfigError 'A definition for option .intStrings\.mergeError. is not of typ
|
||||||
checkConfigError 'A definition for option .intStrings\.badTagError. is not of type .attribute-tagged union' config.intStrings.badTagError ./types-attrTag.nix
|
checkConfigError 'A definition for option .intStrings\.badTagError. is not of type .attribute-tagged union' config.intStrings.badTagError ./types-attrTag.nix
|
||||||
checkConfigError 'A definition for option .intStrings\.badTagTypeError\.left. is not of type .signed integer.' config.intStrings.badTagTypeError.left ./types-attrTag.nix
|
checkConfigError 'A definition for option .intStrings\.badTagTypeError\.left. is not of type .signed integer.' config.intStrings.badTagTypeError.left ./types-attrTag.nix
|
||||||
checkConfigError 'A definition for option .nested\.right\.left. is not of type .signed integer.' config.nested.right.left ./types-attrTag.nix
|
checkConfigError 'A definition for option .nested\.right\.left. is not of type .signed integer.' config.nested.right.left ./types-attrTag.nix
|
||||||
|
checkConfigError 'In attrTag/attrTagWith, each tag value must be an option, but tag int was a bare type, not wrapped in mkOption.' config.opt.int ./types-attrTag-wrong-decl.nix
|
||||||
|
|
||||||
# types.pathInStore
|
# types.pathInStore
|
||||||
checkConfigOutput '".*/store/0lz9p8xhf89kb1c1kk6jxrzskaiygnlh-bash-5.2-p15.drv"' config.pathInStore.ok1 ./types.nix
|
checkConfigOutput '".*/store/0lz9p8xhf89kb1c1kk6jxrzskaiygnlh-bash-5.2-p15.drv"' config.pathInStore.ok1 ./types.nix
|
||||||
|
|
14
lib/tests/modules/types-attrTag-wrong-decl.nix
Normal file
14
lib/tests/modules/types-attrTag-wrong-decl.nix
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{ lib, ... }:
|
||||||
|
let
|
||||||
|
inherit (lib) types mkOption;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
opt = mkOption {
|
||||||
|
type = types.attrTag {
|
||||||
|
int = types.int;
|
||||||
|
};
|
||||||
|
default = { int = 1; };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ let
|
||||||
isList
|
isList
|
||||||
isString
|
isString
|
||||||
isStorePath
|
isStorePath
|
||||||
|
throwIf
|
||||||
toDerivation
|
toDerivation
|
||||||
toList
|
toList
|
||||||
;
|
;
|
||||||
|
@ -627,7 +628,13 @@ rec {
|
||||||
mapAttrs
|
mapAttrs
|
||||||
(n: opt:
|
(n: opt:
|
||||||
builtins.addErrorContext "while checking that attrTag tag ${lib.strings.escapeNixIdentifier n} is an option with a type${inAttrPosSuffix args.tags n}" (
|
builtins.addErrorContext "while checking that attrTag tag ${lib.strings.escapeNixIdentifier n} is an option with a type${inAttrPosSuffix args.tags n}" (
|
||||||
assert opt._type == "option";
|
throwIf (opt._type or null != "option")
|
||||||
|
"In attrTag/attrTagWith, each tag value must be an option, but tag ${lib.strings.escapeNixIdentifier n} ${
|
||||||
|
if opt?_type then
|
||||||
|
if opt._type == "option-type"
|
||||||
|
then "was a bare type, not wrapped in mkOption."
|
||||||
|
else "was of type ${lib.strings.escapeNixString opt._type}."
|
||||||
|
else "was not."}"
|
||||||
opt // {
|
opt // {
|
||||||
declarations = opt.declarations or (
|
declarations = opt.declarations or (
|
||||||
let pos = builtins.unsafeGetAttrPos n args.tags;
|
let pos = builtins.unsafeGetAttrPos n args.tags;
|
||||||
|
|
Loading…
Reference in a new issue