feat(tvix/eval): implement builtins.toXML
Change-Id: I009efc53a8e98f0650ae660c4decd8216e8a06e7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7835 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
This commit is contained in:
parent
1786b4c835
commit
d365b09226
11 changed files with 189 additions and 0 deletions
|
@ -5,12 +5,14 @@ use std::io;
|
|||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::str::Utf8Error;
|
||||
use std::string::FromUtf8Error;
|
||||
use std::sync::Arc;
|
||||
use std::{fmt::Debug, fmt::Display, num::ParseIntError};
|
||||
|
||||
use codemap::{File, Span};
|
||||
use codemap_diagnostic::{ColorConfig, Diagnostic, Emitter, Level, SpanLabel, SpanStyle};
|
||||
use smol_str::SmolStr;
|
||||
use xml::writer::Error as XmlError;
|
||||
|
||||
use crate::{SourceCode, Value};
|
||||
|
||||
|
@ -138,6 +140,9 @@ pub enum ErrorKind {
|
|||
formals_span: Span,
|
||||
},
|
||||
|
||||
/// Errors while serialising to XML.
|
||||
Xml(Rc<XmlError>),
|
||||
|
||||
/// Variant for code paths that are known bugs in Tvix (usually
|
||||
/// issues with the compiler/VM interaction).
|
||||
TvixBug {
|
||||
|
@ -164,6 +169,7 @@ impl error::Error for Error {
|
|||
errors.first().map(|e| e as &dyn error::Error)
|
||||
}
|
||||
ErrorKind::IO { error, .. } => Some(error.as_ref()),
|
||||
ErrorKind::Xml(error) => Some(error.as_ref()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -181,6 +187,18 @@ impl From<Utf8Error> for ErrorKind {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<FromUtf8Error> for ErrorKind {
|
||||
fn from(_: FromUtf8Error) -> Self {
|
||||
Self::NotImplemented("FromUtf8Error not handled: https://b.tvl.fyi/issues/189")
|
||||
}
|
||||
}
|
||||
|
||||
impl From<XmlError> for ErrorKind {
|
||||
fn from(err: XmlError) -> Self {
|
||||
Self::Xml(Rc::new(err))
|
||||
}
|
||||
}
|
||||
|
||||
/// Implementation used if errors occur while forcing thunks (which
|
||||
/// can potentially be threaded through a few contexts, i.e. nested
|
||||
/// thunks).
|
||||
|
@ -392,6 +410,8 @@ to a missing value in the attribute set(s) included via `with`."#,
|
|||
)
|
||||
}
|
||||
|
||||
ErrorKind::Xml(error) => write!(f, "failed to serialise to XML: {error}"),
|
||||
|
||||
ErrorKind::TvixBug { msg, metadata } => {
|
||||
write!(f, "Tvix bug: {}", msg)?;
|
||||
|
||||
|
@ -689,6 +709,7 @@ impl Error {
|
|||
| ErrorKind::ImportCompilerError { .. }
|
||||
| ErrorKind::IO { .. }
|
||||
| ErrorKind::FromJsonError(_)
|
||||
| ErrorKind::Xml(_)
|
||||
| ErrorKind::TvixBug { .. }
|
||||
| ErrorKind::NotImplemented(_) => return None,
|
||||
};
|
||||
|
@ -731,6 +752,7 @@ impl Error {
|
|||
ErrorKind::UnexpectedArgument { .. } => "E031",
|
||||
ErrorKind::RelativePathResolution(_) => "E032",
|
||||
ErrorKind::DivisionByZero => "E033",
|
||||
ErrorKind::Xml(_) => "E034",
|
||||
|
||||
// Special error code that is not part of the normal
|
||||
// ordering.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue