runefs/
error.rs

1//! Error management.
2
3use std::io;
4use thiserror::Error;
5
6pub(crate) type Result<T> = std::result::Result<T, Error>;
7
8/// Super error type for all runefs errors.
9#[derive(Error, Debug)]
10pub enum Error {
11    /// Wrapper for the std::io::Error type.
12    #[error(transparent)]
13    Io(#[from] io::Error),
14    #[error(transparent)]
15    Read(#[from] ReadError),
16    #[error(transparent)]
17    Compression(#[from] CompressionUnsupported),
18    /// Clarification error for failed parsers.
19    #[error(transparent)]
20    Parse(#[from] ParseError),
21}
22
23impl From<nom::Err<()>> for Error {
24    #[inline]
25    fn from(_: nom::Err<()>) -> Self {
26        Self::Parse(ParseError::Unknown)
27    }
28}
29
30#[derive(Error, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
31pub enum ReadError {
32    #[error("index {0} not found")]
33    IndexNotFound(u8),
34    #[error("index {idx} does not contain archive group {arc}")]
35    ArchiveNotFound { idx: u8, arc: u32 },
36    #[error("sector archive id was {0} but expected {1}")]
37    SectorArchiveMismatch(u32, u32),
38    #[error("sector chunk was {0} but expected {1}")]
39    SectorChunkMismatch(usize, usize),
40    #[error("sector next was {0} but expected {1}")]
41    SectorNextMismatch(u32, u32),
42    #[error("sector parent index id was {0} but expected {1}")]
43    SectorIndexMismatch(u8, u8),
44}
45
46#[derive(Error, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
47#[error("unsupported compression type {0}")]
48pub struct CompressionUnsupported(pub(crate) u8);
49
50#[derive(Error, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
51pub enum ParseError {
52    #[error("unknown parser error")]
53    Unknown,
54    #[error("unable to parse archive {0}, unexpected eof")]
55    Archive(u32),
56    #[error("unable to parse child sector of parent {0}, unexpected eof")]
57    Sector(usize),
58}