From 0a13d267f0aa0ab1c70b6ac0e0ee8a44071b3d40 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 2 Sep 2022 00:13:30 +0300 Subject: fix(tvix/eval): thread thunk forcing errors through correctly With this, if an error occurs while forcing a thunk (which is very likely) it is threaded through to the top by wrapping it in the ErrorKind::ThunkForce variant. We could use this to generate "stacktrace-like" error output if we wanted, or simply jump through and discard everything except the innermost error. Change-Id: I3c1c8708c2f73ae062815adf490ce935b1979da8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6409 Reviewed-by: sterni Tested-by: BuildkiteCI --- tvix/eval/src/errors.rs | 4 ++++ tvix/eval/src/value/thunk.rs | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'tvix/eval') diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs index 59142f2efe64..5f1a24b54b4b 100644 --- a/tvix/eval/src/errors.rs +++ b/tvix/eval/src/errors.rs @@ -48,6 +48,10 @@ pub enum ErrorKind { // These are user-generated errors through builtins. Throw(String), Abort(String), + + // An error occured while forcing a thunk, and needs to be chained + // up. + ThunkForce(Box), } #[derive(Clone, Debug)] diff --git a/tvix/eval/src/value/thunk.rs b/tvix/eval/src/value/thunk.rs index c2552284fe20..4fd41689c70c 100644 --- a/tvix/eval/src/value/thunk.rs +++ b/tvix/eval/src/value/thunk.rs @@ -85,9 +85,9 @@ impl Thunk { std::mem::replace(&mut *thunk_mut, ThunkRepr::Blackhole) { vm.call(lambda, upvalues, 0); - // TODO: find a cheap way to actually retain - // the original error span - *thunk_mut = ThunkRepr::Evaluated(vm.run().map_err(|e| e.kind)?); + *thunk_mut = ThunkRepr::Evaluated( + vm.run().map_err(|e| ErrorKind::ThunkForce(Box::new(e)))?, + ); } } } -- cgit 1.4.1