From 85b3f17007825b023d549d8e926322797e08ce6d Mon Sep 17 00:00:00 2001 From: William Carroll Date: Mon, 5 Sep 2022 11:41:50 -0700 Subject: feat(tvix/eval): Support builtins.head TL;DR: - support `builtins.head` - define `ErrorKind::IndexOutOfBounds` and canonical error code - support basic unit tests Change-Id: I859107ffb4e220cba1be8c2ac41d1913dcca37ff Reviewed-on: https://cl.tvl.fyi/c/depot/+/6544 Reviewed-by: wpcarro Autosubmit: wpcarro Reviewed-by: sterni Reviewed-by: tazjin Tested-by: BuildkiteCI --- tvix/eval/src/errors.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tvix/eval/src/errors.rs') diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs index 086cc9d905..a84c931d0a 100644 --- a/tvix/eval/src/errors.rs +++ b/tvix/eval/src/errors.rs @@ -25,6 +25,11 @@ pub enum ErrorKind { name: String, }, + // Attempted to index into a list beyond its boundaries. + IndexOutOfBounds { + index: usize, + }, + TypeError { expected: &'static str, actual: &'static str, @@ -123,6 +128,10 @@ impl Error { name ), + ErrorKind::IndexOutOfBounds { index } => { + format!("list index '{}' is out of bounds", index) + } + ErrorKind::TypeError { expected, actual } => format!( "expected value of type '{}', but found a '{}'", expected, actual @@ -208,6 +217,7 @@ to a missing value in the attribute set(s) included via `with`."#, ErrorKind::DuplicateAttrsKey { .. } => "E016", ErrorKind::ThunkForce(_) => "E017", ErrorKind::NotCoercibleToString { .. } => "E018", + ErrorKind::IndexOutOfBounds { .. } => "E019", ErrorKind::NotImplemented(_) => "E999", } } -- cgit 1.4.1