From dd50af4923a71461262f3113022548edff545b79 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Fri, 26 Jun 2009 12:42:00 +0000 Subject: [PATCH] Add a description of values which cause a bad type the failure. svn path=/nixpkgs/trunk/; revision=16054 --- pkgs/lib/debug.nix | 2 ++ pkgs/lib/options.nix | 16 ++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pkgs/lib/debug.nix b/pkgs/lib/debug.nix index 18b5e1db9d4..c05f540e503 100644 --- a/pkgs/lib/debug.nix +++ b/pkgs/lib/debug.nix @@ -43,6 +43,8 @@ rec { traceCall2 = n : f : a : b : let t = n2 : x : traceShowValMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a) (t "arg 2" b)); traceCall3 = n : f : a : b : c : let t = n2 : x : traceShowValMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a) (t "arg 2" b) (t "arg 3" c)); + traceValIfNot = c: x: + if c x then true else trace (showVal x) false; /* Evaluate a set of tests. A test is an attribute set {expr, expected}, denoting an expression and its expected result. The diff --git a/pkgs/lib/options.nix b/pkgs/lib/options.nix index 1d6b7061473..6f408090738 100644 --- a/pkgs/lib/options.nix +++ b/pkgs/lib/options.nix @@ -163,37 +163,37 @@ rec { bool = mkOptionType { name = "boolean"; - check = builtins.isBool; + check = lib.traceValIfNot builtins.isBool; merge = fold lib.or false; }; int = mkOptionType { name = "integer"; - check = builtins.isInt; + check = lib.traceValIfNot builtins.isInt; }; string = mkOptionType { name = "string"; - check = x: builtins ? isString -> builtins.isString x; + check = lib.traceValIfNot (x: builtins ? isString -> builtins.isString x); merge = lib.concatStrings; }; attrs = mkOptionType { name = "attribute set"; - check = builtins.isAttrs; + check = lib.traceValIfNot builtins.isAttrs; merge = fold lib.mergeAttrs {}; }; # derivation is a reserved keyword. package = mkOptionType { name = "derivation"; - check = x: builtins.isAttrs x && x ? outPath; + check = lib.traceValIfNot isDerivation; }; list = elemType: mkOptionType { name = "list of ${elemType.name}s"; - check = value: isList value && all elemType.check value; + check = value: lib.traceValIfNot isList value && all elemType.check value; merge = concatLists; iter = f: path: list: map (elemType.iter f (path + ".*")) list; fold = op: nul: list: lib.fold (e: l: elemType.fold op l e) nul list; @@ -203,7 +203,7 @@ rec { attrsOf = elemType: mkOptionType { name = "attribute set of ${elemType}s"; - check = x: builtins.isAttrs x + check = x: lib.traceValIfNot builtins.isAttrs x && fold (e: v: v && elemType.check e) true (lib.attrValues x); merge = fold lib.mergeAttrs {}; iter = f: path: set: lib.mapAttrs (name: elemType.iter f (path + "." + name)) set; @@ -230,7 +230,7 @@ rec { optionSet = mkOptionType { name = "option set"; - check = x: builtins.isAttrs x; + check = x: lib.traceValIfNot builtins.isAttrs x; hasOptions = true; };