From 5990cce95f562ed185f55cb9bc3f230265d2ab9d Mon Sep 17 00:00:00 2001 From: Jan Malakhovski Date: Thu, 19 Mar 2015 15:48:54 +0000 Subject: lib: cleanup a little bit, add traceIf --- lib/debug.nix | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/debug.nix') diff --git a/lib/debug.nix b/lib/debug.nix index 8852c22981c5..2d10d981114c 100644 --- a/lib/debug.nix +++ b/lib/debug.nix @@ -13,10 +13,11 @@ rec { addErrorContextToAttrs = lib.mapAttrs (a: v: lib.addErrorContext "while evaluating ${a}" v); + traceIf = p: msg: x: if p then trace msg x else x; - traceVal = x: builtins.trace x x; - traceXMLVal = x: builtins.trace (builtins.toXML x) x; - traceXMLValMarked = str: x: builtins.trace (str + builtins.toXML x) x; + traceVal = x: trace x x; + traceXMLVal = x: trace (builtins.toXML x) x; + traceXMLValMarked = str: x: trace (str + builtins.toXML x) x; # this can help debug your code as well - designed to not produce thousands of lines traceShowVal = x : trace (showVal x) x; @@ -42,6 +43,7 @@ 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)); + # FIXME: rename this? traceValIfNot = c: x: if c x then true else trace (showVal x) false; @@ -106,6 +108,6 @@ rec { ) else let r = strict expr; - in builtins.trace "${str}\n result:\n${builtins.toXML r}" r + in trace "${str}\n result:\n${builtins.toXML r}" r ); } -- cgit v1.2.3