summary refs log tree commit diff
path: root/lib/debug.nix
diff options
context:
space:
mode:
authorJan Malakhovski <oxij@oxij.org>2015-03-19 15:48:54 +0000
committerJan Malakhovski <oxij@oxij.org>2015-03-26 12:43:42 +0000
commit5990cce95f562ed185f55cb9bc3f230265d2ab9d (patch)
tree22a664d7e29c8570c01131f7e1023491161de9cd /lib/debug.nix
parent9a75c1d7c8ee19046ce67f2dc725821d2d5452fa (diff)
downloadnixlib-5990cce95f562ed185f55cb9bc3f230265d2ab9d.tar
nixlib-5990cce95f562ed185f55cb9bc3f230265d2ab9d.tar.gz
nixlib-5990cce95f562ed185f55cb9bc3f230265d2ab9d.tar.bz2
nixlib-5990cce95f562ed185f55cb9bc3f230265d2ab9d.tar.lz
nixlib-5990cce95f562ed185f55cb9bc3f230265d2ab9d.tar.xz
nixlib-5990cce95f562ed185f55cb9bc3f230265d2ab9d.tar.zst
nixlib-5990cce95f562ed185f55cb9bc3f230265d2ab9d.zip
lib: cleanup a little bit, add traceIf
Diffstat (limited to 'lib/debug.nix')
-rw-r--r--lib/debug.nix10
1 files changed, 6 insertions, 4 deletions
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
       );
 }