log/error.rs
1//! Error types for OpenData Log operations.
2//!
3//! This module defines [`Error`], the primary error type for all log
4//! operations, along with a convenient [`Result`] type alias.
5
6use common::coordinator::WriteError;
7use common::{SequenceError, StorageError};
8
9/// Error type for OpenData Log operations.
10///
11/// This enum captures all possible error conditions that can occur when
12/// interacting with the log, including storage failures, encoding issues,
13/// and invalid input.
14///
15/// # Error Categories
16///
17/// - [`Storage`](Error::Storage): Errors from the underlying SlateDB storage layer,
18/// such as I/O failures or corruption.
19/// - [`Encoding`](Error::Encoding): Errors during serialization or deserialization
20/// of log entries.
21/// - [`InvalidInput`](Error::InvalidInput): Errors caused by invalid parameters or
22/// arguments provided by the caller.
23/// - [`Internal`](Error::Internal): Unexpected internal errors that indicate bugs
24/// or invariant violations.
25#[derive(Debug, Clone, PartialEq, Eq)]
26pub enum Error {
27 /// Storage-related errors from the underlying SlateDB layer.
28 ///
29 /// These errors typically indicate I/O failures, corruption, or
30 /// issues with the object store backend.
31 Storage(String),
32
33 /// Encoding or decoding errors.
34 ///
35 /// These errors occur when serializing records for storage or
36 /// deserializing entries during reads.
37 Encoding(String),
38
39 /// Invalid input or parameter errors.
40 ///
41 /// These errors indicate that the caller provided invalid arguments,
42 /// such as empty keys or malformed sequence ranges.
43 InvalidInput(String),
44
45 /// Internal errors indicating bugs or invariant violations.
46 ///
47 /// These errors should not occur during normal operation and
48 /// typically indicate a bug in the implementation.
49 Internal(String),
50}
51
52impl std::error::Error for Error {}
53
54impl std::fmt::Display for Error {
55 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56 match self {
57 Error::Storage(msg) => write!(f, "Storage error: {}", msg),
58 Error::Encoding(msg) => write!(f, "Encoding error: {}", msg),
59 Error::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
60 Error::Internal(msg) => write!(f, "Internal error: {}", msg),
61 }
62 }
63}
64
65impl From<StorageError> for Error {
66 fn from(err: StorageError) -> Self {
67 match err {
68 StorageError::Storage(msg) => Error::Storage(msg),
69 StorageError::Internal(msg) => Error::Internal(msg),
70 }
71 }
72}
73
74impl From<SequenceError> for Error {
75 fn from(err: SequenceError) -> Self {
76 match err {
77 SequenceError::Storage(storage_err) => Error::from(storage_err),
78 SequenceError::Deserialize(de_err) => Error::Encoding(de_err.message),
79 }
80 }
81}
82
83impl From<WriteError> for Error {
84 fn from(err: WriteError) -> Self {
85 match err {
86 WriteError::Backpressure => Error::Internal("write queue full".into()),
87 WriteError::Shutdown => Error::Internal("coordinator shut down".into()),
88 WriteError::ApplyError(_, msg) => Error::Internal(msg),
89 WriteError::FlushError(msg) => Error::Storage(msg),
90 WriteError::Internal(msg) => Error::Internal(msg),
91 }
92 }
93}
94
95impl From<&str> for Error {
96 fn from(msg: &str) -> Self {
97 Error::InvalidInput(msg.to_string())
98 }
99}
100
101/// Result type alias for OpenData Log operations.
102///
103/// This is a convenience alias for `std::result::Result<T, Error>`.
104pub type Result<T> = std::result::Result<T, Error>;