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: {0}")]
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 #[error("The related Pak source has been dropped, so the opperation could not continue.")]
28 PakDropped,
29 #[error("Tried to get PakRef value even though it has not been fetched yet. Must run fetch first.")]
30 PakRefNotFetched,
31}
32
33pub type PqlResult<T> = Result<T, PqlError>;
34
35#[derive(Error, Debug)]
36pub enum PqlError {
37 #[error("Reached end of file unexpectedly at the end of a group.")]
38 EndOfFile,
39 #[error("")]
40 NoMatch,
41 #[error("Unexpected Token: Got `{0:?}` while expecting '{1}`.")]
42 UnexpectedToken(PqlToken, String)
43}
44
45impl PqlError {
46 pub fn is_no_match(&self) -> bool {
47 matches!(self, PqlError::NoMatch)
48 }
49}