chore(tvix/eval): implement std::error::Error for tvix_eval::Error
This makes it easier to interface this error with other crates. Change-Id: I4947ea6097608f8c0427fb94a819ef748d94ea4b Reviewed-on: https://cl.tvl.fyi/c/depot/+/7711 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
parent
31973890a9
commit
49ee3e3b14
2 changed files with 20 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
use crate::spans::ToSpan;
|
use crate::spans::ToSpan;
|
||||||
use crate::value::{CoercionKind, NixString};
|
use crate::value::{CoercionKind, NixString};
|
||||||
|
use std::error;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -150,6 +151,24 @@ pub enum ErrorKind {
|
||||||
NotImplemented(&'static str),
|
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 {
|
impl From<ParseIntError> for ErrorKind {
|
||||||
fn from(e: ParseIntError) -> Self {
|
fn from(e: ParseIntError) -> Self {
|
||||||
Self::ParseIntError(e)
|
Self::ParseIntError(e)
|
||||||
|
|
|
@ -15,7 +15,7 @@ use codemap::{CodeMap, Span};
|
||||||
|
|
||||||
/// Tracks all source code in a Tvix evaluation for accurate error
|
/// Tracks all source code in a Tvix evaluation for accurate error
|
||||||
/// reporting.
|
/// reporting.
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct SourceCode(Rc<RefCell<CodeMap>>);
|
pub struct SourceCode(Rc<RefCell<CodeMap>>);
|
||||||
|
|
||||||
impl SourceCode {
|
impl SourceCode {
|
||||||
|
|
Loading…
Reference in a new issue