pak_db/
error.rs

1use thiserror::Error;
2
3use crate::query::pql::PqlToken;
4
5pub type PakResult<T> = Result<T, PakError>;
6
7#[derive(Error, Debug)]
8pub enum PakError {
9    #[error("The source of the Pak is currenty being used by a seporate opperation.")]
10    SourceInUse,
11    #[error("Type mismatch error: {0} found, {1} expected")]
12    TypeMismatchError(String, String),
13    #[error("Was unable to update rules item: {0}")]
14    UpdateRuleItemError(String),
15    #[error("Was unable to insert rules item: {0}")]
16    InsertRuleItemError(String),
17    #[error("There was an error packing the module: {0}")]
18    BincodeError(#[from] Box<bincode::ErrorKind>),
19    #[error("{0}")]
20    FileError(#[from] std::io::Error),
21    #[error("PQL Error")]
22    PqlError(#[from] PqlError),
23    #[error("Unable to find index `{0}` in Pak. Make sure that this index is correctly spelled.")]
24    InvalidIndex(String),
25    #[error("Before interacting with a Pak file, identifier match check failed. This pointer must come from another file, or might be the wrong version.")]
26    PakIdentifierMismatch
27}
28
29pub type PqlResult<T> = Result<T, PqlError>;
30
31#[derive(Error, Debug)]
32pub enum PqlError {
33    #[error("Reached end of file unexpectedly at the end of a group.")]
34    EndOfFile,
35    #[error("")]
36    NoMatch,
37    #[error("Unexpected Token: Got `{0:?}` while expecting '{1}`.")]
38    UnexpectedToken(PqlToken, String)
39}
40
41impl PqlError {
42    pub fn is_no_match(&self) -> bool {
43        matches!(self, PqlError::NoMatch)
44    }
45}