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/compiler/mod.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'tvix/eval/src/compiler/mod.rs') diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index 92084b031c6c..4a50a3be4935 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -157,12 +157,14 @@ impl<'observer> Compiler<'observer> { let mut root_dir = match location { Some(dir) if cfg!(target_arch = "wasm32") || dir.is_absolute() => Ok(dir), _ => { - let current_dir = std::env::current_dir().map_err(|e| Error { - kind: ErrorKind::RelativePathResolution(format!( - "could not determine current directory: {}", - e - )), - span: file.span, + let current_dir = std::env::current_dir().map_err(|e| { + Error::new( + ErrorKind::RelativePathResolution(format!( + "could not determine current directory: {}", + e + )), + file.span, + ) })?; if let Some(dir) = location { Ok(current_dir.join(dir)) @@ -1220,7 +1222,7 @@ impl Compiler<'_> { fn emit_error(&mut self, node: &N, kind: ErrorKind) { let span = self.span_for(node); - self.errors.push(Error { kind, span }) + self.errors.push(Error::new(kind, span)) } } -- cgit 1.4.1