composefs_storage/error.rs
1//! Error types for the cstorage library.
2//!
3//! This module defines the error types used throughout the library. All operations
4//! that can fail return a [`Result<T>`] which is an alias for `Result<T, StorageError>`.
5//!
6//! # Error Categories
7//!
8//! Errors are organized into several categories:
9//!
10//! - **Storage errors**: [`RootNotFound`], [`InvalidStorage`]
11//! - **Entity errors**: [`LayerNotFound`], [`ImageNotFound`]
12//! - **Link resolution**: [`LinkReadError`]
13//! - **Tar-split processing**: [`TarSplitError`]
14//! - **System errors**: [`Io`], [`JsonParse`]
15//!
16//! [`RootNotFound`]: StorageError::RootNotFound
17//! [`InvalidStorage`]: StorageError::InvalidStorage
18//! [`LayerNotFound`]: StorageError::LayerNotFound
19//! [`ImageNotFound`]: StorageError::ImageNotFound
20//! [`LinkReadError`]: StorageError::LinkReadError
21//! [`TarSplitError`]: StorageError::TarSplitError
22//! [`Io`]: StorageError::Io
23//! [`JsonParse`]: StorageError::JsonParse
24
25use std::path::PathBuf;
26
27/// Result type alias for operations that may return a StorageError.
28pub type Result<T> = std::result::Result<T, StorageError>;
29
30/// Error types for storage operations.
31#[derive(Debug, thiserror::Error)]
32pub enum StorageError {
33 /// Storage root directory was not found at the specified path.
34 #[error("storage root not found at {0}")]
35 RootNotFound(PathBuf),
36
37 /// Storage validation failed with the provided reason.
38 #[error("invalid storage: {0}")]
39 InvalidStorage(String),
40
41 /// The requested layer was not found.
42 #[error("layer not found: {0}")]
43 LayerNotFound(String),
44
45 /// The requested image was not found.
46 #[error("image not found: {0}")]
47 ImageNotFound(String),
48
49 /// Failed to read a link file.
50 #[error("failed to read link file: {0}")]
51 LinkReadError(String),
52
53 /// Error related to tar-split processing.
54 #[error("tar-split error: {0}")]
55 TarSplitError(String),
56
57 /// I/O error occurred during file operations.
58 #[error("I/O error: {0}")]
59 Io(#[from] std::io::Error),
60
61 /// JSON parsing error occurred.
62 #[error("JSON parse error: {0}")]
63 JsonParse(#[from] serde_json::Error),
64}