librashader/librashader-presets/src/error.rs

49 lines
1.5 KiB
Rust
Raw Normal View History

use std::path::PathBuf;
use thiserror::Error;
2022-12-01 14:50:57 +11:00
/// Error type for preset parsing.
#[derive(Error, Debug)]
pub enum ParsePresetError {
2022-12-01 14:50:57 +11:00
/// An error occurred when tokenizing the preset file.
#[error("shader preset lexing error")]
LexerError { offset: usize, row: u32, col: usize },
2022-12-01 14:50:57 +11:00
/// An error occurred when parsing the preset file.
#[error("shader preset parse error")]
ParserError {
offset: usize,
row: u32,
col: usize,
kind: ParseErrorKind,
},
2022-12-01 14:50:57 +11:00
/// The scale type was invalid.
#[error("invalid scale type")]
InvalidScaleType(String),
2022-12-01 14:50:57 +11:00
/// The preset reference depth exceeded 16.
#[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")]
RootPathWasNotAbsolute,
2022-12-01 14:50:57 +11:00
/// An IO error occurred when reading the shader preset.
#[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.
#[error("expected utf8 bytes but got invalid utf8")]
Utf8Error(Vec<u8>),
}
2022-12-01 14:50:57 +11:00
/// The kind of error that may occur in parsing.
#[derive(Debug)]
pub enum ParseErrorKind {
2022-12-01 14:50:57 +11:00
/// Expected an indexed key (i.e. `shader0`, `shader1`, ...)
Index(&'static str),
2022-12-01 14:50:57 +11:00
/// Expected a signed integer.
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.
Float,
2022-12-01 14:50:57 +11:00
/// Expected a boolean.
Bool,
}