1use bstr::ByteSlice;
2
3use crate::{
4 SymlinkTargetError,
5 path::{PathComponent, PathComponentError},
6};
7
8#[derive(Debug, thiserror::Error, PartialEq)]
10pub enum ValidateNodeError {
11 #[error("invalid digest length: {0}")]
13 InvalidDigestLen(usize),
14 #[error("Invalid symlink target: {0}")]
16 InvalidSymlinkTarget(SymlinkTargetError),
17 #[error("invalid hash type: expected a 'blake3-' prefixed digest")]
19 InvalidHashType,
20}
21
22impl From<crate::digests::Error> for ValidateNodeError {
23 fn from(e: crate::digests::Error) -> Self {
24 match e {
25 crate::digests::Error::InvalidDigestLen(n) => ValidateNodeError::InvalidDigestLen(n),
26 crate::digests::Error::InvalidHashType => ValidateNodeError::InvalidHashType,
27 }
28 }
29}
30
31#[derive(Debug, thiserror::Error, PartialEq)]
34pub enum DirectoryError {
35 #[error("{:?} is a duplicate name", .0)]
37 DuplicateName(PathComponent),
38 #[error("invalid node with name {}: {:?}", .0.as_bstr(), .1.to_string())]
40 InvalidNode(bytes::Bytes, ValidateNodeError),
41 #[error("Total size exceeds u64::MAX")]
42 SizeOverflow,
43 #[error("Invalid name: {0}")]
45 InvalidName(PathComponentError),
46 #[error("Name is set when it shouldn't")]
49 NameInAnonymousNode,
50 #[error("{:?} is not sorted", .0.as_bstr())]
52 WrongSorting(bytes::Bytes),
53 #[error("No entry set")]
55 NoEntrySet,
56}