Skip to main content

lora_wal/recorder/
errors.rs

1//! Error types and the [`WroteCommit`] flag returned from
2//! [`super::WalRecorder::commit`].
3
4use thiserror::Error;
5
6use crate::errors::WalError;
7
8/// Whether [`super::WalRecorder::commit`] actually wrote a `TxCommit` to the
9/// log. Read-only queries — those that never trigger
10/// `MutationRecorder::record` — return [`WroteCommit::No`] so the host avoids
11/// any WAL I/O just to record an empty transaction.
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum WroteCommit {
14    /// A `TxBegin` and matching `TxCommit` were written through
15    /// `Wal::commit_tx`; the configured flush policy has already run.
16    Yes,
17    /// No mutation events fired during the query, so neither `TxBegin`
18    /// nor `TxCommit` was appended. Caller can skip `flush()` entirely.
19    No,
20}
21
22impl WroteCommit {
23    pub fn wrote(self) -> bool {
24        matches!(self, Self::Yes)
25    }
26}
27
28#[derive(Debug, Error)]
29pub enum WalCommitError {
30    #[error("WAL commit failed: {0}")]
31    Commit(#[source] WalError),
32    #[error("WAL flush failed: {0}")]
33    Flush(#[source] WalError),
34}
35
36#[derive(Debug, Error)]
37#[error("WAL poisoned: {reason}")]
38pub struct WalPoisonError {
39    pub(super) reason: String,
40}
41
42impl WalPoisonError {
43    pub fn reason(&self) -> &str {
44        &self.reason
45    }
46}
47
48#[derive(Debug, Error)]
49pub enum WalBufferedCommitError {
50    #[error("WAL arm failed: {0}")]
51    Arm(#[source] WalError),
52    #[error("WAL poisoned: {0}")]
53    Poisoned(String),
54    #[error("WAL poisoned during commit replay: {0}")]
55    ReplayPoisoned(String),
56    #[error(transparent)]
57    Commit(#[from] WalCommitError),
58}