1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! Error types for file splitting and joining operations.
use crate::ChunkAddress;
use thiserror::Error;
/// Errors from file splitting and joining operations.
#[derive(Error, Debug)]
pub enum FileError {
/// Write exceeded the declared span length.
#[error("write past span length: wrote {written} bytes, span is {span}")]
WritePastSpan {
/// Declared span length.
span: u64,
/// Bytes written so far.
written: u64,
},
/// Chunk data exceeds maximum allowed size.
#[error("chunk too large: max {max}, got {actual}")]
ChunkTooLarge {
/// Maximum allowed size.
max: usize,
/// Actual size.
actual: usize,
},
/// Chunk store failed to store a chunk.
#[error("store error: {0}")]
Store(Box<dyn std::error::Error + Send + Sync>),
/// Chunk getter failed to retrieve a chunk.
#[error("getter error: {0}")]
Getter(Box<dyn std::error::Error + Send + Sync>),
/// Invalid chunk reference encountered during tree traversal.
#[error("invalid reference at level {level}")]
InvalidReference {
/// Tree level where the invalid reference was found.
level: usize,
},
/// Required chunk was not found.
#[error("chunk not found: {0}")]
ChunkNotFound(ChunkAddress),
/// Span value doesn't match expected value.
#[error("span mismatch: expected {expected}, got {actual}")]
SpanMismatch {
/// Expected span value.
expected: u64,
/// Actual span value.
actual: u64,
},
/// Underlying chunk error.
#[error("chunk error: {0}")]
Chunk(#[from] crate::chunk::error::ChunkError),
/// Encryption error.
#[error("encryption error: {0}")]
Encryption(#[from] crate::chunk::encryption::EncryptionError),
/// Invalid entry reference length (expected 32 or 64 bytes).
#[error("invalid entry reference length: {len} (expected 32 or 64)")]
InvalidEntryRef {
/// Actual byte length of the reference.
len: usize,
},
/// Expected a content chunk but got a different chunk type.
#[error("expected content chunk, got {type_name}")]
InvalidChunkType {
/// Name of the chunk type that was received.
type_name: &'static str,
},
}
impl FileError {
/// Create a store error from any error type.
pub fn store<E: std::error::Error + Send + Sync + 'static>(err: E) -> Self {
Self::Store(Box::new(err))
}
/// Create a getter error from any error type.
pub fn getter<E: std::error::Error + Send + Sync + 'static>(err: E) -> Self {
Self::Getter(Box::new(err))
}
}
/// Result type for file operations.
pub type Result<T> = std::result::Result<T, FileError>;