2022-10-20 13:47:43 +11:00
|
|
|
use std::path::PathBuf;
|
|
|
|
use thiserror::Error;
|
|
|
|
|
2022-12-01 14:50:57 +11:00
|
|
|
/// Error type for preset parsing.
|
2022-10-20 13:47:43 +11:00
|
|
|
#[derive(Error, Debug)]
|
|
|
|
pub enum ParsePresetError {
|
2022-12-01 14:50:57 +11:00
|
|
|
/// An error occurred when tokenizing the preset file.
|
2022-10-20 16:59:15 +11:00
|
|
|
#[error("shader preset lexing error")]
|
2022-10-20 13:47:43 +11:00
|
|
|
LexerError { offset: usize, row: u32, col: usize },
|
2022-12-01 14:50:57 +11:00
|
|
|
/// An error occurred when parsing the preset file.
|
2022-10-20 13:47:43 +11:00
|
|
|
#[error("shader preset parse error")]
|
2022-10-20 16:59:15 +11:00
|
|
|
ParserError {
|
|
|
|
offset: usize,
|
|
|
|
row: u32,
|
|
|
|
col: usize,
|
|
|
|
kind: ParseErrorKind,
|
|
|
|
},
|
2022-12-01 14:50:57 +11:00
|
|
|
/// The scale type was invalid.
|
2022-10-20 13:47:43 +11:00
|
|
|
#[error("invalid scale type")]
|
|
|
|
InvalidScaleType(String),
|
2022-12-01 14:50:57 +11:00
|
|
|
/// The preset reference depth exceeded 16.
|
2022-10-20 13:47:43 +11:00
|
|
|
#[error("exceeded maximum reference depth (16)")]
|
|
|
|
ExceededReferenceDepth,
|
2022-12-01 14:50:57 +11:00
|
|
|
/// An absolute path could not be found to resolve the shader preset against.
|
|
|
|
#[error("shader presets must be resolved against an absolute path")]
|
2022-10-20 13:47:43 +11:00
|
|
|
RootPathWasNotAbsolute,
|
2022-12-01 14:50:57 +11:00
|
|
|
/// An IO error occurred when reading the shader preset.
|
2022-10-20 13:47:43 +11:00
|
|
|
#[error("the file was not found during resolution")]
|
|
|
|
IOError(PathBuf, std::io::Error),
|
2022-12-01 14:50:57 +11:00
|
|
|
/// The shader preset did not contain valid UTF-8 bytes.
|
2022-10-20 13:47:43 +11:00
|
|
|
#[error("expected utf8 bytes but got invalid utf8")]
|
|
|
|
Utf8Error(Vec<u8>),
|
|
|
|
}
|
2022-10-20 16:59:15 +11:00
|
|
|
|
2022-12-01 14:50:57 +11:00
|
|
|
/// The kind of error that may occur in parsing.
|
2022-10-20 16:59:15 +11:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum ParseErrorKind {
|
2022-12-01 14:50:57 +11:00
|
|
|
/// Expected an indexed key (i.e. `shader0`, `shader1`, ...)
|
2022-10-20 16:59:15 +11:00
|
|
|
Index(&'static str),
|
2022-12-01 14:50:57 +11:00
|
|
|
/// Expected a signed integer.
|
2022-10-20 16:59:15 +11:00
|
|
|
Int,
|
2022-12-01 14:50:57 +11:00
|
|
|
/// Expected an unsigned integer.
|
2022-10-20 17:26:21 +11:00
|
|
|
UnsignedInt,
|
2022-12-01 14:50:57 +11:00
|
|
|
/// Expected a float.
|
2022-10-20 16:59:15 +11:00
|
|
|
Float,
|
2022-12-01 14:50:57 +11:00
|
|
|
/// Expected a boolean.
|
2022-10-20 16:59:15 +11:00
|
|
|
Bool,
|
|
|
|
}
|