Skip to main content

kithara_storage/
error.rs

1#![forbid(unsafe_code)]
2
3use std::io;
4
5use thiserror::Error;
6
7/// Result type used by `kithara-storage`.
8pub type StorageResult<T> = Result<T, StorageError>;
9
10/// Errors produced by storage primitives.
11///
12/// Notes:
13/// - We intentionally keep this error type fairly small at this stage.
14/// - Higher-level crates may wrap this error to add domain context (resource key, URL, etc.).
15#[derive(Debug, Error)]
16pub enum StorageError {
17    #[error("io error: {0}")]
18    Io(#[from] io::Error),
19
20    #[cfg(not(target_arch = "wasm32"))]
21    #[error("mmap error: {0}")]
22    Mmap(#[from] mmap_io::MmapIoError),
23
24    #[error("invalid range: start {start} >= end {end}")]
25    InvalidRange { start: u64, end: u64 },
26
27    #[error("resource failed: {0}")]
28    Failed(String),
29
30    /// The atomic-chunked temp path is already claimed by another writer
31    /// (different `AssetStore` instance, possibly cross-process). The
32    /// caller should either wait for the holder to release (commit or
33    /// drop) and retry, or fall through to a read-only / passthrough
34    /// view of the canonical path once committed.
35    ///
36    /// Reported by [`crate::AtomicChunked::open`] when the sibling temp
37    /// file already exists on disk. Filesystem-level signal — no
38    /// in-process registry involved.
39    #[error("atomic-chunked tmp claimed by another writer: {0}")]
40    TmpClaimed(std::path::PathBuf),
41
42    /// A read targeted a resource whose processing pipeline has not yet
43    /// committed (e.g. AES-128 segment reactivated for re-fetch). The
44    /// underlying bytes either still hold ciphertext or are stale; the
45    /// caller should treat this as transient and retry once the writer
46    /// completes its commit.
47    #[error("processed resource is not readable before commit")]
48    NotReadable,
49
50    #[error("operation cancelled")]
51    Cancelled,
52}