5 /* Throw if pred is false, else return pred.
6 Intended to be used to augment asserts with helpful error messages.
12 assert assertMsg ("foo" == "bar") "foo is not bar, silly"; ""
13 stderr> error: foo is not bar, silly
16 assertMsg :: Bool -> String -> Bool
18 # TODO(Profpatsch): add tests that check stderr
20 # Predicate that needs to succeed, otherwise `msg` is thrown
22 # Message to throw in case `pred` fails
24 pred || builtins.throw msg;
26 /* Specialized `assertMsg` for checking if `val` is one of the elements
27 of the list `xs`. Useful for checking enums.
30 let sslLibrary = "libressl";
31 in assertOneOf "sslLibrary" sslLibrary [ "openssl" "bearssl" ]
32 stderr> error: sslLibrary must be one of [
35 stderr> ], but is: "libressl"
38 assertOneOf :: String -> ComparableVal -> List ComparableVal -> Bool
41 # The name of the variable the user entered `val` into, for inclusion in the error message
43 # The value of what the user provided, to be compared against the values in `xs`
45 # The list of valid values
49 "${name} must be one of ${
50 lib.generators.toPretty {} xs}, but is: ${
51 lib.generators.toPretty {} val}";