about summary refs log tree commit diff
path: root/tvix/eval/src/errors.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/errors.rs')
-rw-r--r--tvix/eval/src/errors.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs
index 0d12f259a5b7..2cef36f757a1 100644
--- a/tvix/eval/src/errors.rs
+++ b/tvix/eval/src/errors.rs
@@ -1,5 +1,6 @@
 use crate::spans::ToSpan;
 use crate::value::{CoercionKind, NixString};
+use std::error;
 use std::io;
 use std::path::PathBuf;
 use std::rc::Rc;
@@ -150,6 +151,24 @@ pub enum ErrorKind {
     NotImplemented(&'static str),
 }
 
+impl error::Error for Error {
+    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
+        match &self.kind {
+            ErrorKind::ThunkForce(err) => err.source(),
+            ErrorKind::ParseErrors(err) => err.first().map(|e| e as &dyn error::Error),
+            ErrorKind::ParseIntError(err) => Some(err),
+            ErrorKind::ImportParseError { errors, .. } => {
+                errors.first().map(|e| e as &dyn error::Error)
+            }
+            ErrorKind::ImportCompilerError { errors, .. } => {
+                errors.first().map(|e| e as &dyn error::Error)
+            }
+            ErrorKind::IO { error, .. } => Some(error.as_ref()),
+            _ => None,
+        }
+    }
+}
+
 impl From<ParseIntError> for ErrorKind {
     fn from(e: ParseIntError) -> Self {
         Self::ParseIntError(e)