From 6b42aef88d80b7e65240ffc21597cf719e811c55 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Fri, 5 Jan 2024 13:31:25 +0200 Subject: fix(tvix/castore): validate Option 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 Reviewed-by: raitobezarius Tested-by: BuildkiteCI --- tvix/castore/src/proto/mod.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'tvix/castore') diff --git a/tvix/castore/src/proto/mod.rs b/tvix/castore/src/proto/mod.rs index c734e8be89ec..9c4df4df53c2 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 { -- cgit 1.4.1