From 167718614429322655fa352d20c754612da8d1a8 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 6 Oct 2022 17:35:15 +0300 Subject: feat(tvix/eval): add some slightly more descriptive span labels Change-Id: I530c491f60a33fdb97e1553b193de51e7ee57d9a Reviewed-on: https://cl.tvl.fyi/c/depot/+/6873 Reviewed-by: wpcarro Autosubmit: tazjin Tested-by: BuildkiteCI --- tvix/eval/src/errors.rs | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'tvix/eval') diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs index 2963e7877dc6..51fece840fae 100644 --- a/tvix/eval/src/errors.rs +++ b/tvix/eval/src/errors.rs @@ -392,7 +392,42 @@ impl Error { /// Create the optional span label displayed as an annotation on /// the underlined span of the error. fn span_label(&self) -> Option { - None + let label = match &self.kind { + ErrorKind::DuplicateAttrsKey { .. } => "in this attribute set", + ErrorKind::InvalidAttributeName(_) => "in this attribute set", + ErrorKind::PathResolution(_) => "in this path literal", + + // The spans for some errors don't have any more descriptive stuff + // in them, or we don't utilise it yet. + ErrorKind::Throw(_) + | ErrorKind::Abort(_) + | ErrorKind::AssertionFailed + | ErrorKind::AttributeNotFound { .. } + | ErrorKind::IndexOutOfBounds { .. } + | ErrorKind::TailEmptyList + | ErrorKind::TypeError { .. } + | ErrorKind::Incomparable { .. } + | ErrorKind::DynamicKeyInScope(_) + | ErrorKind::UnknownStaticVariable + | ErrorKind::UnknownDynamicVariable(_) + | ErrorKind::VariableAlreadyDefined(_) + | ErrorKind::NotCallable(_) + | ErrorKind::InfiniteRecursion + | ErrorKind::ParseErrors(_) + | ErrorKind::ThunkForce(_) + | ErrorKind::NotCoercibleToString { .. } + | ErrorKind::NotAnAbsolutePath(_) + | ErrorKind::ParseIntError(_) + | ErrorKind::NegativeLength { .. } + | ErrorKind::UnmergeableInherit { .. } + | ErrorKind::UnmergeableValue + | ErrorKind::ReadFileError { .. } + | ErrorKind::ImportParseError { .. } + | ErrorKind::ImportCompilerError { .. } + | ErrorKind::NotImplemented(_) => return None, + }; + + Some(label.into()) } /// Create the primary error message displayed to users. -- cgit 1.4.1