tryEval
builtins.tryEval
Takes 1 arguments
e
Try to shallowly evaluate e. Return a set containing the
attributes success
(true
if e evaluated successfully,
false
if an error was thrown) and value
, equalling e if
successful and false
otherwise. tryEval
only prevents
errors created by throw
or assert
from being thrown.
Errors tryEval
doesn't catch are, for example, those created
by abort
and type errors generated by builtins. Also note that
this doesn't evaluate e deeply, so let e = { x = throw ""; }; in (builtins.tryEval e).success
is true
. Using
builtins.deepSeq
one can get the expected result:
let e = { x = throw ""; }; in (builtins.tryEval (builtins.deepSeq e e)).success
is
false
.
tryEval
intentionally does not return the error message, because that risks bringing non-determinism into the evaluation result, and it would become very difficult to improve error reporting without breaking existing expressions.
Instead, use builtins.addErrorContext
to add context to the error message, and use a Nix unit testing tool for testing.
Noogle detected
tryEval :: a
Implementation
This function is implemented in c++ and is part of the native nix runtime.