about summary refs log tree commit diff
path: root/tvix/eval/src/builtins/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/builtins/mod.rs')
-rw-r--r--tvix/eval/src/builtins/mod.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index 08b8299e4803..1fc833641766 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -431,6 +431,21 @@ fn pure_builtins() -> Vec<Builtin> {
         Builtin::new("throw", &[true], |args: Vec<Value>, _: &mut VM| {
             Err(ErrorKind::Throw(args[0].to_str()?.to_string()))
         }),
+        Builtin::new("tryEval", &[false], |args: Vec<Value>, vm: &mut VM| {
+            let mut res = BTreeMap::new();
+            match args[0].force(vm) {
+                Ok(value) => {
+                    res.insert("value".into(), (*value).clone());
+                    res.insert("success".into(), true.into());
+                }
+                Err(e) if e.is_catchable() => {
+                    res.insert("value".into(), false.into());
+                    res.insert("success".into(), false.into());
+                }
+                Err(e) => return Err(e),
+            }
+            Ok(Value::attrs(NixAttrs::from_map(res)))
+        }),
         // coerce_to_string forces for us
         Builtin::new("toString", &[false], |args: Vec<Value>, vm: &mut VM| {
             args[0]