From 9b1a266197d4edb55d40415464f7106c72ad6149 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 6 Oct 2022 17:26:24 +0300 Subject: feat(tvix/eval): chain error spans for thunk errors Adds secondary spans for errors that occur deeply nested within a thunk. This is pretty raw right now, there's technically nothing stopping one of these error chains from being a hundred thunks deep into code, producing unmanageable error output. We should trim these down according to some heuristics (e.g. when crossing file boundaries, o r just - for starters - beginning and end). Change-Id: Ia73892512737850b6fa3e07cabc37fa9c534c4d5 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6872 Reviewed-by: sterni Autosubmit: tazjin Tested-by: BuildkiteCI --- tvix/eval/src/errors.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs index 72c98120729e..2963e7877dc6 100644 --- a/tvix/eval/src/errors.rs +++ b/tvix/eval/src/errors.rs @@ -601,6 +601,27 @@ to a missing value in the attribute set(s) included via `with`."#, spans_for_parse_errors(&file, errors) } + // Unwrap thunk errors to the innermost one + // TODO: limit the number of intermediates! + ErrorKind::ThunkForce(err) => { + let mut labels = err.spans(source); + + // Only add this thunk to the "cause chain" if it span isn't + // exactly identical to the next-higher level, which is very + // common for the last thunk in a chain. + if let Some(label) = labels.last() { + if label.span != self.span { + labels.push(SpanLabel { + label: Some("while evaluating this".into()), + span: self.span, + style: SpanStyle::Secondary, + }); + } + } + + labels + } + // All other errors pretty much have the same shape. _ => { vec![SpanLabel { -- cgit 1.4.1