about summary refs log tree commit diff
path: root/tvix/eval/src/errors.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-01-15T11·52+0300
committertazjin <tazjin@tvl.su>2023-01-16T13·43+0000
commitd365b092262013e074f0fe800a1955032eaa2fd9 (patch)
treed5c32fecf48fdcc2ec9697accd2be69c1c977a1a /tvix/eval/src/errors.rs
parent1786b4c835cbce619ddae77ffeebe89b24d50c0e (diff)
feat(tvix/eval): implement builtins.toXML r/5664
Change-Id: I009efc53a8e98f0650ae660c4decd8216e8a06e7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7835
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/errors.rs')
-rw-r--r--tvix/eval/src/errors.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs
index 6a463d9f96df..67ef509ba9d7 100644
--- a/tvix/eval/src/errors.rs
+++ b/tvix/eval/src/errors.rs
@@ -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.