From 972c867b365631f771f6933cd9a6384316d5aea5 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 16 Jan 2023 20:02:33 +0300 Subject: feat(tvix/eval): add error contexts to annotate error kinds This makes it possible for users to add additional context to an error, which will then be rendered as an additional secondary span in the formatted error output. We should strive to do this basically anywhere errors are raised that can occur multiple times, *especially* during type casts. This was triggered by me debugging a type cast error attached to a fairly large-ish span (a builtin invocation). Change-Id: I51be41fabee00cf04de973935daf34fe6424e76f Reviewed-on: https://cl.tvl.fyi/c/depot/+/7849 Tested-by: BuildkiteCI Reviewed-by: flokli --- tvix/eval/src/vm.rs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'tvix/eval/src/vm.rs') diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs index 3dece0641281..60006ea76f9c 100644 --- a/tvix/eval/src/vm.rs +++ b/tvix/eval/src/vm.rs @@ -134,12 +134,7 @@ macro_rules! fallible { ( $self:ident, $body:expr) => { match $body { Ok(result) => result, - Err(kind) => { - return Err(Error { - kind, - span: $self.current_span(), - }) - } + Err(kind) => return Err(Error::new(kind, $self.current_span())), } }; } @@ -281,10 +276,7 @@ impl<'o> VM<'o> { /// Construct an error from the given ErrorKind and the source /// span of the current instruction. pub fn error(&self, kind: ErrorKind) -> Error { - Error { - kind, - span: self.current_span(), - } + Error::new(kind, self.current_span()) } /// Push an already constructed warning. @@ -1197,10 +1189,7 @@ pub fn run_lambda( value .deep_force(&mut vm, &mut Default::default()) - .map_err(|kind| Error { - kind, - span: root_span, - })?; + .map_err(|kind| Error::new(kind, root_span))?; Ok(RuntimeResult { value, -- cgit 1.4.1