about summary refs log tree commit diff
path: root/nix
diff options
context:
space:
mode:
authorzseri <zseri.devel@ytrizja.de>2021-12-27T03·52+0100
committerclbot <clbot@tvl.fyi>2021-12-27T08·20+0000
commit00adb6e8f347ea6fee328641c4413946a41af5a2 (patch)
tree721b498bc9bab73116fbfad9b03678b3cab51771 /nix
parent9c0925b6d226d3f9265ee3cb59d1c1552381d0e6 (diff)
feat(nix/yants): improve error message for errornous predicate r/3463
while trying to yantsify `mkSecrets` in https://cl.tvl.fyi/c/depot/+/4688,
I(zseri) needed to debug a failing evaluation which boiled down
to a result.ok containing something which wasn't boolean,
but the error message didn't indicate where that value came from.

I debugged yants and found that the only place which didn't
simply combine boolean values or use functions which always
return booleans, I managed to isolate the error to the
`pred v` expression. To avoid the necessity to debug yants
to find this, I improve the error message for this case
to mention that
- a restriction predicate is invalid
- what's the name of the failing restriction
- the unexpected predicate return value

Change-Id: I6c570a33ccc5afc445f208e2e8855c49fb37abaf
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4698
Tested-by: BuildkiteCI
Reviewed-by: zseri <zseri.devel@ytrizja.de>
Reviewed-by: tazjin <mail@tazj.in>
Autosubmit: zseri <zseri.devel@ytrizja.de>
Diffstat (limited to 'nix')
-rw-r--r--nix/yants/default.nix13
1 files changed, 9 insertions, 4 deletions
diff --git a/nix/yants/default.nix b/nix/yants/default.nix
index 058444d27be9..2bbf4dd15a9e 100644
--- a/nix/yants/default.nix
+++ b/nix/yants/default.nix
@@ -317,10 +317,15 @@ in lib.fix (self: {
       in
         if !(t.checkToBool res)
         then res
-        else {
-          ok = pred v;
-          err = "${prettyPrint v} does not conform to restriction '${restriction}'";
-        };
+        else
+          let
+            iok = pred v;
+          in if isBool iok then {
+            ok = iok;
+            err = "${prettyPrint v} does not conform to restriction '${restriction}'";
+          } else
+            # use throw here to avoid spamming the build log
+            throw "restriction '${restriction}' predicate returned unexpected value '${prettyPrint iok}' instead of boolean";
   };
 
 })