about summary refs log tree commit diff
path: root/tvix/eval/src/errors.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-01-24T14·54+0100
committerclbot <clbot@tvl.fyi>2023-01-25T07·49+0000
commite0b05c0fa6562bc7d3c87a66c6557ad74fdbbd8f (patch)
tree9777bf85c45f0527428c38974b102a0acf0455f2 /tvix/eval/src/errors.rs
parent1facd889bba724cf20ea14422ee1e57440b3e761 (diff)
feat(tvix/eval): implement builtins.fromTOML r/5754
This allows parsing TOML from Tvix. We can enable the eval-okay-fromTOML
testcase from nix_tests. It uses the `toml` crate, and the serde
integration it brings with it.

Change-Id: Ic6f95aacf2aeb890116629b409752deac49dd655
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7920
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/errors.rs')
-rw-r--r--tvix/eval/src/errors.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs
index ccc2d89764..8c0d612420 100644
--- a/tvix/eval/src/errors.rs
+++ b/tvix/eval/src/errors.rs
@@ -134,6 +134,9 @@ pub enum ErrorKind {
     /// Errors converting JSON to a value
     FromJsonError(String),
 
+    /// Errors converting TOML to a value
+    FromTomlError(String),
+
     /// An unexpected argument was supplied to a function that takes formal parameters
     UnexpectedArgument {
         arg: NixString,
@@ -246,6 +249,12 @@ impl From<serde_json::Error> for ErrorKind {
     }
 }
 
+impl From<toml::de::Error> for ErrorKind {
+    fn from(err: toml::de::Error) -> Self {
+        Self::FromTomlError(format!("error in TOML serialization: {err}"))
+    }
+}
+
 #[derive(Clone, Debug)]
 pub struct Error {
     kind: ErrorKind,
@@ -434,6 +443,10 @@ to a missing value in the attribute set(s) included via `with`."#,
                 write!(f, "Error converting JSON to a Nix value: {msg}")
             }
 
+            ErrorKind::FromTomlError(msg) => {
+                write!(f, "Error converting TOML to a Nix value: {msg}")
+            }
+
             ErrorKind::UnexpectedArgument { arg, .. } => {
                 write!(
                     f,
@@ -749,6 +762,7 @@ impl Error {
             | ErrorKind::ImportCompilerError { .. }
             | ErrorKind::IO { .. }
             | ErrorKind::FromJsonError(_)
+            | ErrorKind::FromTomlError(_)
             | ErrorKind::Xml(_)
             | ErrorKind::TvixError(_)
             | ErrorKind::TvixBug { .. }
@@ -795,6 +809,7 @@ impl Error {
             ErrorKind::RelativePathResolution(_) => "E032",
             ErrorKind::DivisionByZero => "E033",
             ErrorKind::Xml(_) => "E034",
+            ErrorKind::FromTomlError(_) => "E035",
 
             // Special error code for errors from other Tvix
             // components. We may want to introduce a code namespacing