1use std::{io, result, string};
2
3use thiserror::Error;
4
5#[derive(Debug, Error)]
6pub enum ChmError {
7 #[error("I/O error: {0}")]
8 Io(#[from] io::Error),
9 #[error("not a valid CHM file: bad ITSF signature or version")]
10 BadItsf,
11 #[error("bad ITSP directory header")]
12 BadItsp,
13 #[error("bad PMGL block signature")]
14 BadPmgl,
15 #[error("bad PMGI block signature")]
16 BadPmgi,
17 #[error("bad LZXC control data")]
18 BadLzxc,
19 #[error("bad LZXC reset table")]
20 BadResetTable,
21 #[error("entry not found: {0}")]
22 NotFound(String),
23 #[error("compressed data unavailable (file has no MSCompressed section)")]
24 NoCompression,
25 #[error("LZX decompression error: {0}")]
26 Lzx(#[from] LzxError),
27 #[error("entry path exceeds maximum length")]
28 PathTooLong,
29 #[error("invalid UTF-8 in entry path")]
30 Utf8(#[from] string::FromUtf8Error),
31 #[error("integer overflow in block/offset calculation")]
32 Overflow,
33}
34
35pub type Result<T> = result::Result<T, ChmError>;
36
37#[derive(Debug, Error)]
38pub enum LzxError {
39 #[error("illegal data in LZX stream")]
40 IllegalData,
41 #[error("data format error in LZX stream")]
42 DataFormat,
43 #[error("invalid LZX window bits: must be 15-21, got {0}")]
44 InvalidWindow(u8),
45}