6 Throw if pred is false, else return pred.
7 Intended to be used to augment asserts with helpful error messages.
13 : Predicate that needs to succeed, otherwise `msg` is thrown
17 : Message to throw in case `pred` fails
22 assertMsg :: Bool -> String -> Bool
27 ## `lib.asserts.assertMsg` usage example
30 assertMsg false "nope"
32 assert assertMsg ("foo" == "bar") "foo is not bar, silly"; ""
33 stderr> error: foo is not bar, silly
38 # TODO(Profpatsch): add tests that check stderr
42 pred || builtins.throw msg;
45 Specialized `assertMsg` for checking if `val` is one of the elements
46 of the list `xs`. Useful for checking enums.
52 : The name of the variable the user entered `val` into, for inclusion in the error message
56 : The value of what the user provided, to be compared against the values in `xs`
60 : The list of valid values
65 assertOneOf :: String -> ComparableVal -> List ComparableVal -> Bool
70 ## `lib.asserts.assertOneOf` usage example
73 let sslLibrary = "libressl";
74 in assertOneOf "sslLibrary" sslLibrary [ "openssl" "bearssl" ]
75 stderr> error: sslLibrary must be one of [
78 stderr> ], but is: "libressl"
89 "${name} must be one of ${
90 lib.generators.toPretty {} xs}, but is: ${
91 lib.generators.toPretty {} val}";
94 Specialized `assertMsg` for checking if every one of `vals` is one of the elements
95 of the list `xs`. Useful for checking lists of supported attributes.
101 : The name of the variable the user entered `val` into, for inclusion in the error message
105 : The list of values of what the user provided, to be compared against the values in `xs`
109 : The list of valid values
114 assertEachOneOf :: String -> List ComparableVal -> List ComparableVal -> Bool
119 ## `lib.asserts.assertEachOneOf` usage example
122 let sslLibraries = [ "libressl" "bearssl" ];
123 in assertEachOneOf "sslLibraries" sslLibraries [ "openssl" "bearssl" ]
124 stderr> error: each element in sslLibraries must be one of [
140 (lib.all (val: lib.elem val xs) vals)
141 "each element in ${name} must be one of ${
142 lib.generators.toPretty {} xs}, but is: ${
143 lib.generators.toPretty {} vals}";