diff --git a/src/front/wgsl.rs b/src/front/wgsl.rs index 0614bf1725..a8004b26ef 100644 --- a/src/front/wgsl.rs +++ b/src/front/wgsl.rs @@ -7,6 +7,8 @@ use crate::{ FastHashMap, }; +use thiserror::Error; + #[derive(Copy, Clone, Debug, PartialEq)] pub enum Token<'a> { Separator(char), @@ -136,33 +138,44 @@ mod lex { } } -#[derive(Debug)] +#[derive(Clone, Debug, Error)] pub enum Error<'a> { + #[error("unexpected token: {0:?}")] Unexpected(Token<'a>), - UnexpectedConstantType(crate::proc::UnexpectedConstantTypeError), + #[error(transparent)] + UnexpectedConstantType(#[from] crate::proc::UnexpectedConstantTypeError), + #[error("unable to parse `{0}` as integer: {1}")] BadInteger(&'a str, std::num::ParseIntError), + #[error("unable to parse `{1}` as float: {1}")] BadFloat(&'a str, std::num::ParseFloatError), + #[error("bad field accessor `{0}`")] BadAccessor(&'a str), + #[error(transparent)] InvalidResolve(ResolveError), + #[error("unknown import: `{0}`")] UnknownImport(&'a str), + #[error("unknown storage class: `{0}`")] UnknownStorageClass(&'a str), + #[error("unknown decoration: `{0}`")] UnknownDecoration(&'a str), + #[error("unknown builtin: `{0}`")] UnknownBuiltin(&'a str), + #[error("unknown shader stage: `{0}`")] UnknownShaderStage(&'a str), + #[error("unknown identifier: `{0}`")] UnknownIdent(&'a str), + #[error("unknown type: `{0}`")] UnknownType(&'a str), + #[error("unknown function: `{0}`")] UnknownFunction(&'a str), + #[error("missing offset for structure member `{0}`")] MissingMemberOffset(&'a str), - MutabilityViolation(&'a str), + //MutabilityViolation(&'a str), + // TODO: these could be replaced with more detailed errors + #[error("other error")] Other, } -impl<'a> From for Error<'a> { - fn from(error: crate::proc::UnexpectedConstantTypeError) -> Self { - Error::UnexpectedConstantType(error) - } -} - #[derive(Clone)] struct Lexer<'a> { input: &'a str, @@ -370,7 +383,8 @@ pub enum Scope { GeneralExpr, } -#[derive(Debug)] +#[derive(Clone, Debug, Error)] +#[error("error while parsing WGSL in scopes {scopes:?} at position {pos:?}: {error}")] pub struct ParseError<'a> { pub error: Error<'a>, pub scopes: Vec, diff --git a/src/proc/typifier.rs b/src/proc/typifier.rs index 044b5ea528..c967bd80c6 100644 --- a/src/proc/typifier.rs +++ b/src/proc/typifier.rs @@ -3,11 +3,13 @@ use crate::{ Type, TypeInner, VectorSize, }; +use thiserror::Error; + pub struct Typifier { types: Vec>, } -#[derive(Debug, thiserror::Error)] +#[derive(Clone, Debug, Error)] pub enum ResolveError { #[error("Invalid index into array")] InvalidAccessIndex, @@ -209,7 +211,8 @@ impl Typifier { } } -#[derive(Debug)] +#[derive(Clone, Debug, Error)] +#[error("mismatched constant type {0:?} expected {1:?}")] pub struct UnexpectedConstantTypeError(crate::ConstantInner, crate::TypeInner); pub fn check_constant_types(