about summary refs log tree commit diff
path: root/tvix/eval/src/builtins
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-24T14·13+0300
committertazjin <tazjin@tvl.su>2022-09-02T12·59+0000
commitbd0fc69f0702d5682ea7fcba6c39a7dc09891368 (patch)
tree280a5065a054cbf4fd780976397d3aab4113a443 /tvix/eval/src/builtins
parent3d0280ec03f927ae4925aae400600a7b96058587 (diff)
feat(tvix/eval): implement 'throw' and 'abort' builtins r/4593
These do essentially the same, but return different error variants as
upstream Nix considers `throw` to be (sometimes) catchable.

Change-Id: I1a9ea84567d46fb37287dbf3f3f67052f9382cca
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6259
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/builtins')
-rw-r--r--tvix/eval/src/builtins/mod.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index 39e29580b4c3..a856538f0d8a 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -8,13 +8,26 @@ use std::{
     rc::Rc,
 };
 
-use crate::value::{Builtin, NixAttrs, NixString, Value};
+use crate::{
+    errors::ErrorKind,
+    value::{Builtin, NixAttrs, NixString, Value},
+};
 
 fn pure_builtins() -> Vec<Builtin> {
     vec![
+        Builtin::new("abort", 1, |mut args| {
+            return Err(
+                ErrorKind::Abort(args.pop().unwrap().to_string()?.as_str().to_owned()).into(),
+            );
+        }),
         Builtin::new("isNull", 1, |args| {
             Ok(Value::Bool(matches!(args[0], Value::Null)))
         }),
+        Builtin::new("throw", 1, |mut args| {
+            return Err(
+                ErrorKind::Throw(args.pop().unwrap().to_string()?.as_str().to_owned()).into(),
+            );
+        }),
         Builtin::new("toString", 1, |args| {
             // TODO: toString is actually not the same as Display
             Ok(Value::String(format!("{}", args[0]).into()))