about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2024-01-05T11·31+0200
committerclbot <clbot@tvl.fyi>2024-01-05T16·43+0000
commit6b42aef88d80b7e65240ffc21597cf719e811c55 (patch)
tree7b4c96a91d678059f54045d1bd003bafd6ac188a /tvix
parentf20969de9b42527518b27e3fb78b6d487780baff (diff)
fix(tvix/castore): validate Option<Node> r/7347
Extend our validation function to also check for the None case.

Change-Id: Ib75f880646d7fb3d66588f1988e61ec18be816a2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10534
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix')
-rw-r--r--tvix/castore/src/proto/mod.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/tvix/castore/src/proto/mod.rs b/tvix/castore/src/proto/mod.rs
index c734e8be89..9c4df4df53 100644
--- a/tvix/castore/src/proto/mod.rs
+++ b/tvix/castore/src/proto/mod.rs
@@ -24,7 +24,7 @@ pub const FILE_DESCRIPTOR_SET: &[u8] = tonic::include_file_descriptor_set!("tvix
 #[cfg(test)]
 mod tests;
 
-/// Errors that can occur during the validation of Directory messages.
+/// Errors that can occur during the validation of [Directory] messages.
 #[derive(Debug, PartialEq, Eq, thiserror::Error)]
 pub enum ValidateDirectoryError {
     /// Elements are not in sorted order
@@ -43,6 +43,8 @@ pub enum ValidateDirectoryError {
 /// Errors that occur during Node validation
 #[derive(Debug, PartialEq, Eq, thiserror::Error)]
 pub enum ValidateNodeError {
+    #[error("No node set")]
+    NoNodeSet,
     /// Invalid digest length encountered
     #[error("Invalid Digest length: {0}")]
     InvalidDigestLen(usize),
@@ -103,6 +105,18 @@ impl NamedNode for node::Node {
     }
 }
 
+impl Node {
+    /// Ensures the node has a valid enum kind (is Some), and passes its
+    // per-enum validation.
+    pub fn validate(&self) -> Result<(), ValidateNodeError> {
+        if let Some(node) = self.node.as_ref() {
+            node.validate()
+        } else {
+            Err(ValidateNodeError::NoNodeSet)
+        }
+    }
+}
+
 impl node::Node {
     /// Returns the node with a new name.
     pub fn rename(self, name: bytes::Bytes) -> Self {