about summary refs log tree commit diff
path: root/tvix/castore/src/proto/mod.rs
diff options
context:
space:
mode:
authoredef <edef@edef.eu>2023-10-27T12·44+0000
committeredef <edef@edef.eu>2023-10-27T13·56+0000
commit621739037fe5cb5fd521851a76ca73812da59e85 (patch)
tree3ac72d319423d61b8d40aa3010342b57af837618 /tvix/castore/src/proto/mod.rs
parente5252720192064c8dfee6b869e8a5859d08e4a94 (diff)
feat(tvix/castore): carry name in ValidateNodeError::InvalidName r/6894
Change-Id: Ica288e94f3f6025d98ef7d56dc5d6f874ec921b7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9861
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/castore/src/proto/mod.rs')
-rw-r--r--tvix/castore/src/proto/mod.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/tvix/castore/src/proto/mod.rs b/tvix/castore/src/proto/mod.rs
index f590c6841336..07892ab79905 100644
--- a/tvix/castore/src/proto/mod.rs
+++ b/tvix/castore/src/proto/mod.rs
@@ -1,7 +1,7 @@
 #![allow(clippy::derive_partial_eq_without_eq, non_snake_case)]
 // https://github.com/hyperium/tonic/issues/1056
 use bstr::ByteSlice;
-use std::{collections::HashSet, iter::Peekable};
+use std::{collections::HashSet, iter::Peekable, str};
 
 use prost::Message;
 
@@ -47,8 +47,8 @@ pub enum ValidateNodeError {
     #[error("Invalid Digest length: {0}")]
     InvalidDigestLen(usize),
     /// Invalid name encountered
-    #[error("Invalid name")]
-    InvalidName,
+    #[error("Invalid name: {}", .0.as_bstr())]
+    InvalidName(Vec<u8>),
     /// Invalid symlink target
     #[error("Invalid symlink target: {}", .0.as_bstr())]
     InvalidSymlinkTarget(Vec<u8>),
@@ -63,9 +63,10 @@ fn validate_node_name(name: &[u8]) -> Result<(), ValidateNodeError> {
         || name.contains(&0x00)
         || name.contains(&b'/')
     {
-        Err(ValidateNodeError::InvalidName)?;
+        Err(ValidateNodeError::InvalidName(name.to_owned()))
+    } else {
+        Ok(())
     }
-    Ok(())
 }
 
 /// NamedNode is implemented for [FileNode], [DirectoryNode] and [SymlinkNode]
@@ -122,14 +123,14 @@ impl node::Node {
                         directory_node.digest.len(),
                     ))?;
                 }
-                validate_node_name(&directory_node.name)?;
+                validate_node_name(&directory_node.name)
             }
             // for a file root node, ensure the digest has the appropriate size.
             node::Node::File(file_node) => {
                 if file_node.digest.len() != B3_LEN {
                     Err(ValidateNodeError::InvalidDigestLen(file_node.digest.len()))?;
                 }
-                validate_node_name(&file_node.name)?;
+                validate_node_name(&file_node.name)
             }
             // ensure the symlink target is not empty and doesn't contain null bytes.
             node::Node::Symlink(symlink_node) => {
@@ -138,10 +139,9 @@ impl node::Node {
                         symlink_node.target.to_vec(),
                     ))?;
                 }
-                validate_node_name(&symlink_node.name)?;
+                validate_node_name(&symlink_node.name)
             }
         }
-        Ok(())
     }
 }