checkAssertWarn
lib.asserts.checkAssertWarn
Docs pulled from | This Revision | about 1 hour ago
Wrap a value with logic that throws an error when assertions fail and emits any warnings.
Inputs
assertions
-
A list of assertions. If any of their
assertion
attrs isfalse
, theirmessage
attrs will be emitted in athrow
. warnings
-
A list of strings to emit as warnings. This function does no filtering on this list.
val
-
A value to return, wrapped in
warn
, if athrow
is not necessary.
Type
checkAssertWarn :: [ { assertion :: Bool; message :: String } ] -> [ String ] -> Any -> Any
Examples
lib.asserts.checkAssertWarn
usage example
checkAssertWarn
[ { assertion = false; message = "Will fail"; } ]
[ ]
null
stderr> error:
stderr> Failed assertions:
stderr> - Will fail
checkAssertWarn
[ { assertion = true; message = "Will not fail"; } ]
[ "Will warn" ]
null
stderr> evaluation warning: Will warn
null
Noogle detected
Implementation
The following is the current implementation of this function.
checkAssertWarn =
assertions: warnings: val:
let
failedAssertions = map (x: x.message) (filter (x: !x.assertion) assertions);
in
if failedAssertions != [ ] then
throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
else
showWarnings warnings val;