feat(tvix/eval): add error variant for threading through errors
This variant is required for external builtins (which in our case includes `derivation`) to thread through reasonable error messages. This has some potential for improvement, but it's an improvement over the status quo of panicking in the external builtins when no appropriate error is available. Change-Id: I7e4bdb0a156c7717092dde30aa4785192182dc66 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7841 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
This commit is contained in:
parent
d365b09226
commit
67addf3b3d
1 changed files with 17 additions and 2 deletions
|
@ -1,5 +1,3 @@
|
|||
use crate::spans::ToSpan;
|
||||
use crate::value::{CoercionKind, NixString};
|
||||
use std::error;
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
|
@ -14,6 +12,8 @@ use codemap_diagnostic::{ColorConfig, Diagnostic, Emitter, Level, SpanLabel, Spa
|
|||
use smol_str::SmolStr;
|
||||
use xml::writer::Error as XmlError;
|
||||
|
||||
use crate::spans::ToSpan;
|
||||
use crate::value::{CoercionKind, NixString};
|
||||
use crate::{SourceCode, Value};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -143,6 +143,10 @@ pub enum ErrorKind {
|
|||
/// Errors while serialising to XML.
|
||||
Xml(Rc<XmlError>),
|
||||
|
||||
/// Variant for errors that bubble up to eval from other Tvix
|
||||
/// components.
|
||||
TvixError(Rc<dyn error::Error>),
|
||||
|
||||
/// Variant for code paths that are known bugs in Tvix (usually
|
||||
/// issues with the compiler/VM interaction).
|
||||
TvixBug {
|
||||
|
@ -170,6 +174,7 @@ impl error::Error for Error {
|
|||
}
|
||||
ErrorKind::IO { error, .. } => Some(error.as_ref()),
|
||||
ErrorKind::Xml(error) => Some(error.as_ref()),
|
||||
ErrorKind::TvixError(error) => Some(error.as_ref()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -412,6 +417,10 @@ to a missing value in the attribute set(s) included via `with`."#,
|
|||
|
||||
ErrorKind::Xml(error) => write!(f, "failed to serialise to XML: {error}"),
|
||||
|
||||
ErrorKind::TvixError(inner_error) => {
|
||||
write!(f, "{inner_error}")
|
||||
}
|
||||
|
||||
ErrorKind::TvixBug { msg, metadata } => {
|
||||
write!(f, "Tvix bug: {}", msg)?;
|
||||
|
||||
|
@ -710,6 +719,7 @@ impl Error {
|
|||
| ErrorKind::IO { .. }
|
||||
| ErrorKind::FromJsonError(_)
|
||||
| ErrorKind::Xml(_)
|
||||
| ErrorKind::TvixError(_)
|
||||
| ErrorKind::TvixBug { .. }
|
||||
| ErrorKind::NotImplemented(_) => return None,
|
||||
};
|
||||
|
@ -754,6 +764,11 @@ impl Error {
|
|||
ErrorKind::DivisionByZero => "E033",
|
||||
ErrorKind::Xml(_) => "E034",
|
||||
|
||||
// Special error code for errors from other Tvix
|
||||
// components. We may want to introduce a code namespacing
|
||||
// system to have these errors pass codes through.
|
||||
ErrorKind::TvixError(_) => "E997",
|
||||
|
||||
// Special error code that is not part of the normal
|
||||
// ordering.
|
||||
ErrorKind::TvixBug { .. } => "E998",
|
||||
|
|
Loading…
Reference in a new issue