mutant_lib/internal_error.rs
1use crate::{index::error::IndexError, network::NetworkError};
2use deadpool::managed::PoolError;
3use never::Never;
4use thiserror::Error;
5use tokio::sync::AcquireError;
6
7/// Represents the primary error type returned by `mutant-lib` functions.
8///
9/// This enum aggregates potential errors from various internal layers (network, storage, etc.)
10/// as well as general operational errors.
11#[derive(Error, Debug, Clone)]
12pub enum Error {
13 /// Errors related to configuration loading or validation.
14 #[error("Configuration Error: {0}")]
15 Config(String),
16
17 /// Errors originating from the network layer (e.g., connection issues, peer discovery failures).
18 #[error("Network Layer Error: {0}")]
19 Network(#[from] NetworkError),
20
21 #[error("Index Layer Error: {0}")]
22 Index(#[from] IndexError),
23
24 // /// Errors originating from the indexing layer (e.g., search failures, index inconsistency).
25 // #[error("Index Layer Error: {0}")]
26 // Index(#[from] IndexError),
27
28 // /// Errors related to pad lifecycle management (e.g., creation, deletion, update failures).
29 // #[error("Pad Lifecycle Layer Error: {0}")]
30 // PadLifecycle(#[from] PadLifecycleError),
31
32 // /// Errors related to data processing or handling (e.g., serialization, deserialization issues).
33 // #[error("Data Operation Layer Error: {0}")]
34 // Data(#[from] DataError),
35 /// Errors occurring within user-provided callback functions.
36 #[error("Callback Error: {0}")]
37 Callback(String),
38
39 /// Indicates that an operation was explicitly cancelled by a user callback.
40 #[error("Operation cancelled by user callback")]
41 OperationCancelled,
42
43 /// Indicates that a requested feature or functionality is not yet implemented.
44 #[error("Feature not yet implemented: {0}")]
45 NotImplemented(String),
46
47 /// Represents unexpected internal errors within the library.
48 #[error("Internal Library Error: {0}")]
49 Internal(String),
50
51 /// Specific error indicating an operation was cancelled by a callback returning `false`.
52 #[error("Callback cancelled operation")]
53 CancelledByCallback,
54
55 /// Specific error indicating a failure reported by a callback mechanism.
56 #[error("Callback failed: {0}")]
57 CallbackFailed(String),
58
59 #[error("Callback error: {0}")]
60 CallbackError(String),
61
62 /// Errors related to the worker pool management (e.g., resource acquisition).
63 #[error("Worker Pool Error: {0}")]
64 PoolError(String),
65
66 /// Indicates a timeout occurred during an operation.
67 #[error("Operation timed out: {0}")]
68 Timeout(String),
69}
70
71// Implementation to convert deadpool PoolError into our internal Error::PoolError
72impl From<PoolError<Never>> for Error {
73 fn from(e: PoolError<Never>) -> Self {
74 Error::PoolError(e.to_string())
75 }
76}
77
78// Implementation to convert tokio AcquireError into our internal Error::PoolError
79impl From<AcquireError> for Error {
80 fn from(e: AcquireError) -> Self {
81 Error::PoolError(format!("Worker pool semaphore acquisition failed: {}", e))
82 }
83}