···
+
Throw if pred is false, else return pred.
+
Intended to be used to augment asserts with helpful error messages.
+
: Predicate that needs to succeed, otherwise `msg` is thrown
+
: Message to throw in case `pred` fails
+
assertMsg :: Bool -> String -> Bool
+
## `lib.asserts.assertMsg` usage example
+
assert assertMsg ("foo" == "bar") "foo is not bar, silly"; ""
+
stderr> error: foo is not bar, silly
# TODO(Profpatsch): add tests that check stderr
pred || builtins.throw msg;
+
Specialized `assertMsg` for checking if `val` is one of the elements
+
of the list `xs`. Useful for checking enums.
+
: The name of the variable the user entered `val` into, for inclusion in the error message
+
: The value of what the user provided, to be compared against the values in `xs`
+
: The list of valid values
+
assertOneOf :: String -> ComparableVal -> List ComparableVal -> Bool
+
## `lib.asserts.assertOneOf` usage example
+
let sslLibrary = "libressl";
+
in assertOneOf "sslLibrary" sslLibrary [ "openssl" "bearssl" ]
+
stderr> error: sslLibrary must be one of [
+
stderr> ], but is: "libressl"
···
lib.generators.toPretty {} xs}, but is: ${
lib.generators.toPretty {} val}";
+
Specialized `assertMsg` for checking if every one of `vals` is one of the elements
+
of the list `xs`. Useful for checking lists of supported attributes.
+
: The name of the variable the user entered `val` into, for inclusion in the error message
+
: The list of values of what the user provided, to be compared against the values in `xs`
+
: The list of valid values
+
assertEachOneOf :: String -> List ComparableVal -> List ComparableVal -> Bool
+
## `lib.asserts.assertEachOneOf` usage example
+
let sslLibraries = [ "libressl" "bearssl" ];
+
in assertEachOneOf "sslLibraries" sslLibraries [ "openssl" "bearssl" ]
+
stderr> error: each element in sslLibraries must be one of [
(lib.all (val: lib.elem val xs) vals)