1use std::path::PathBuf;
2
3use thiserror::Error;
4
5#[derive(Debug, Error)]
10#[non_exhaustive]
11pub enum Error {
12 #[error("I/O error at {path}: {source}")]
13 Io {
14 path: PathBuf,
15 #[source]
16 source: std::io::Error,
17 },
18
19 #[error("unsupported compression magic bytes {magic:02x?} in {path}")]
20 UnsupportedCompression { path: PathBuf, magic: Vec<u8> },
21
22 #[error(transparent)]
23 Rds(#[from] rd_rds::Error),
24
25 #[error(transparent)]
26 RdsFile(#[from] rd_rds::file::ReadError),
27
28 #[error("malformed help-db index: {0}")]
29 MalformedIndex(String),
30
31 #[error("help-db index exceeds the {limit}-byte limit")]
32 IndexSizeLimitExceeded { limit: usize },
33
34 #[error("stored help-db record exceeds the {limit}-byte limit")]
35 StoredRecordSizeLimitExceeded { limit: usize },
36
37 #[error("decompressed help-db record exceeds the {limit}-byte limit")]
38 DecompressedRecordSizeLimitExceeded { limit: usize },
39
40 #[error("help database changed while it was being read: {path}")]
41 DatabaseChanged { path: PathBuf },
42
43 #[error("record compression {compression:?} is not supported")]
44 UnsupportedRecordCompression {
45 compression: rd_rds::lazyload::Compression,
46 },
47
48 #[error("reference {key:?} does not address a direct record")]
49 UnsupportedReference { key: String },
50
51 #[error("unknown topic {topic:?}")]
52 UnknownTopic { topic: String },
53
54 #[error("unknown reference key {key:?}")]
55 UnknownReference { key: String },
56
57 #[error(
58 "record size mismatch: the 4-byte length prefix declares {expected} bytes but zlib decompression produced {actual} bytes"
59 )]
60 RecordSizeMismatch { expected: usize, actual: usize },
61}
62
63impl Error {
64 pub(crate) fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
65 Self::Io {
66 path: path.into(),
67 source,
68 }
69 }
70}