fix(tvix/castore): validate Option<Node>

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
This commit is contained in:
Florian Klink 2024-01-05 13:31:25 +02:00 committed by clbot
parent f20969de9b
commit 6b42aef88d

View file

@ -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 {