1use std::io;
2use std::path::PathBuf;
3
4use thiserror::Error;
5
6use crate::lsn::Lsn;
7
8#[derive(Debug, Error)]
17pub enum WalError {
18 #[error("WAL I/O error: {0}")]
19 Io(#[from] io::Error),
20
21 #[error("WAL record could not be encoded: {0}")]
22 Encode(String),
23
24 #[error("WAL record could not be decoded: {0}")]
25 Decode(String),
26
27 #[error("WAL record CRC mismatch at lsn {lsn}: expected 0x{expected:08x}, got 0x{actual:08x}")]
28 CrcMismatch {
29 lsn: Lsn,
30 expected: u32,
31 actual: u32,
32 },
33
34 #[error("WAL record truncated: expected {expected} bytes, got {actual}")]
35 Truncated { expected: usize, actual: usize },
36
37 #[error("unknown WAL record kind: {0}")]
38 UnknownKind(u8),
39
40 #[error("WAL segment header is malformed: {0}")]
41 BadSegmentHeader(&'static str),
42
43 #[error("WAL structure is malformed: {0}")]
44 Malformed(String),
45
46 #[error("WAL directory is already open by another live handle: {dir}")]
47 AlreadyOpen { dir: PathBuf },
48
49 #[error("WAL is poisoned: a previous append failed and the log is no longer durable")]
50 Poisoned,
51}