1use std::path::PathBuf;
2
3#[derive(Debug, thiserror::Error)]
4pub enum Error {
5 #[error("io error on {path}: {source}")]
6 Io {
7 path: PathBuf,
8 #[source]
9 source: std::io::Error,
10 },
11
12 #[error(transparent)]
13 Arrow(#[from] arrow_schema::ArrowError),
14
15 #[error("dictionary key space exhausted for column `{0}`; seal the block")]
18 DictionaryFull(&'static str),
19
20 #[error("{path} is not an Arrow IPC file (bad ARROW1 magic)")]
21 BadMagic { path: PathBuf },
22
23 #[error("{path} failed checksum: footer says {expected:#010x}, body hashes to {actual:#010x}")]
24 BadChecksum {
25 path: PathBuf,
26 expected: u32,
27 actual: u32,
28 },
29
30 #[error("{path} has no {key} in its IPC footer metadata; not a Mira block")]
31 MissingMetadata { path: PathBuf, key: &'static str },
32
33 #[error("{path}: this block's body cannot be decoded: {source}")]
45 Undecodable {
46 path: PathBuf,
47 #[source]
48 source: arrow_schema::ArrowError,
49 },
50
51 #[error(
54 "{path} is on {fs}, a network filesystem. Mira reads blocks through mmap, \
55 and on {fs} a server-side error surfaces as SIGBUS — a signal, not an \
56 error, with no recovery path from Rust. Point --data-dir at a local \
57 block device (in Kubernetes: a local PV, an EBS/PD volume, or an \
58 emptyDir, not an NFS/CSI network mount)."
59 )]
60 NetworkFilesystem { path: PathBuf, fs: String },
61
62 #[error(
65 "{path} is not writable: {source}. Mira writes nowhere else, so this is \
66 fatal at startup rather than degraded at 3am. Check that the mount is \
67 read-write and that this process owns the path (in Kubernetes: a \
68 volume mounted readOnly, or a missing fsGroup)."
69 )]
70 NotWritable {
71 path: PathBuf,
72 #[source]
73 source: std::io::Error,
74 },
75
76 #[error("export of {len} bytes exceeds the {max}-byte WAL frame limit")]
80 WalFrameTooLarge { len: usize, max: u32 },
81
82 #[error("{path}: corrupt write-ahead log frame: {why}")]
87 WalCorrupt { path: PathBuf, why: &'static str },
88
89 #[error("{path}: write-ahead log version {found}, this build writes {expected}")]
93 WalVersion {
94 path: PathBuf,
95 found: u16,
96 expected: u16,
97 },
98}
99
100pub type Result<T, E = Error> = std::result::Result<T, E>;
101
102pub(crate) trait IoContext<T> {
103 fn ctx(self, path: impl Into<PathBuf>) -> Result<T>;
104}
105
106impl<T> IoContext<T> for std::io::Result<T> {
107 fn ctx(self, path: impl Into<PathBuf>) -> Result<T> {
108 self.map_err(|source| Error::Io {
109 path: path.into(),
110 source,
111 })
112 }
113}