From 4fd18cbc9a756ea51dd04fa7bde9cfc79f4f8fa3 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Mon, 10 Oct 2022 11:54:53 -0400 Subject: feat(tvix/eval): Implement builtins.tryEval With asserts compiled using conditional jumps, this ends up being quite straightforward - the only real tricky bit is that we have to know whether an error can or can't be handled. Change-Id: I75617da73b7a9c5cdd888c0e26ae81d2c5c0d714 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6924 Reviewed-by: sterni Autosubmit: grfn Tested-by: BuildkiteCI --- tvix/eval/src/errors.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tvix/eval/src/errors.rs') diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs index a7d54d51bb27..3ba3404a8d12 100644 --- a/tvix/eval/src/errors.rs +++ b/tvix/eval/src/errors.rs @@ -158,6 +158,17 @@ impl From for ErrorKind { } } +impl ErrorKind { + /// Returns `true` if this error can be caught by `builtins.tryEval` + pub fn is_catchable(&self) -> bool { + match self { + Self::Throw(_) | Self::AssertionFailed => true, + Self::ThunkForce(err) => err.kind.is_catchable(), + _ => false, + } + } +} + #[derive(Clone, Debug)] pub struct Error { pub kind: ErrorKind, -- cgit 1.4.1