about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-10-06T14·26+0300
committerclbot <clbot@tvl.fyi>2022-10-08T17·27+0000
commit9b1a266197d4edb55d40415464f7106c72ad6149 (patch)
tree0ba3150662865f3f9ce4be34394acb43f838da53
parent1e2d323a7c5b554f69902987b57c9d47d57e7eea (diff)
feat(tvix/eval): chain error spans for thunk errors r/5064
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 <sternenseemann@systemli.org>
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
-rw-r--r--tvix/eval/src/errors.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs
index 72c9812072..2963e7877d 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 {