Skip to main content

drasi_lib/wal/
error.rs

1// Copyright 2025 The Drasi Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Error types for the Write-Ahead Log plugin contract.
16
17use thiserror::Error;
18
19/// Errors that can occur during WAL operations.
20///
21/// All variants include source_id context where relevant, since a single
22/// `WalProvider` instance typically serves multiple sources.
23#[derive(Debug, Error)]
24pub enum WalError {
25    /// The WAL for the given source has reached its configured maximum event capacity
26    /// and the policy is [`CapacityPolicy::RejectIncoming`](super::CapacityPolicy::RejectIncoming).
27    #[error("WAL capacity exhausted for source '{0}'")]
28    CapacityExhausted(String),
29
30    /// The requested replay position has been pruned and is older than the
31    /// oldest retained sequence. Reading from a sequence greater than `head`
32    /// is not an error — it returns an empty result (the caller is caught up).
33    #[error("Position {requested} unavailable for source '{source_id}' (oldest available: {oldest_available:?})")]
34    PositionUnavailable {
35        source_id: String,
36        requested: u64,
37        oldest_available: Option<u64>,
38    },
39
40    /// Called a WAL operation for a source that was never registered.
41    #[error("Source '{0}' is not registered with the WAL provider")]
42    SourceNotRegistered(String),
43
44    /// Attempted to register a source that is already registered with a different config.
45    #[error("Source '{0}' is already registered with a different config")]
46    SourceAlreadyRegistered(String),
47
48    /// The supplied source_id is not acceptable to this provider (e.g., contains
49    /// path separators, `..`, or other characters a file-backed provider cannot
50    /// safely map to disk).
51    #[error("Invalid source_id '{0}': {1}")]
52    InvalidSourceId(String, String),
53
54    /// The event is not valid for WAL storage (e.g., `SourceChange::Future`).
55    #[error("Invalid event: {0}")]
56    InvalidEvent(String),
57
58    /// Configuration validation failed (e.g., `max_events` below `MIN_MAX_EVENTS`).
59    #[error("Invalid configuration: {0}")]
60    InvalidConfig(String),
61
62    /// An error in the underlying storage backend.
63    #[error("Storage error: {0}")]
64    StorageError(String),
65
66    /// An error during event serialization or deserialization.
67    #[error("Serialization error: {0}")]
68    SerializationError(String),
69}