nectar_primitives/file/
error.rs1use crate::ChunkAddress;
4use thiserror::Error;
5
6#[non_exhaustive]
8#[derive(Error, Debug)]
9pub enum FileError {
10 #[error("write past span length: wrote {written} bytes, span is {span}")]
12 WritePastSpan {
13 span: u64,
15 written: u64,
17 },
18
19 #[error("chunk too large: max {max}, got {actual}")]
21 ChunkTooLarge {
22 max: usize,
24 actual: usize,
26 },
27
28 #[error("store error")]
30 Store(#[source] Box<dyn std::error::Error + Send + Sync>),
31
32 #[error("sink error: {0}")]
36 Sink(String),
37
38 #[error("getter error")]
40 Getter(#[source] Box<dyn std::error::Error + Send + Sync>),
41
42 #[error("invalid reference at level {level}")]
44 InvalidReference {
45 level: usize,
47 },
48
49 #[error("chunk not found: {0}")]
51 ChunkNotFound(ChunkAddress),
52
53 #[error("span mismatch: expected {expected}, got {actual}")]
55 SpanMismatch {
56 expected: u64,
58 actual: u64,
60 },
61
62 #[error("chunk error: {0}")]
64 Chunk(#[from] crate::chunk::error::ChunkError),
65
66 #[error("encryption error: {0}")]
68 Encryption(#[from] crate::chunk::encryption::EncryptionError),
69
70 #[error("invalid entry reference length: {len} (expected 32 or 64)")]
72 InvalidEntryRef {
73 len: usize,
75 },
76
77 #[error("expected content chunk, got {type_name}")]
79 InvalidChunkType {
80 type_name: &'static str,
82 },
83}
84
85impl FileError {
86 pub fn store<E: std::error::Error + Send + Sync + 'static>(err: E) -> Self {
88 Self::Store(Box::new(err))
89 }
90
91 pub fn getter<E: std::error::Error + Send + Sync + 'static>(err: E) -> Self {
93 Self::Getter(Box::new(err))
94 }
95
96 pub fn sink<E: std::error::Error>(err: E) -> Self {
99 Self::Sink(err.to_string())
100 }
101}
102
103pub type Result<T> = std::result::Result<T, FileError>;