1use std::fmt::{Debug, Display};
2use thiserror::Error;
3
4use crate::Rule;
5
6pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Error, Debug)]
9pub enum Error {
10 #[error(transparent)]
11 Io(#[from] std::io::Error),
12
13 #[error(transparent)]
14 ParserError(#[from] Box<pest::error::Error<Rule>>),
15
16 #[error("failed to resolve referenced input `{0}`")]
17 InputResolveError(String),
18
19 #[error("attempted to use dot-notation on non-object value at `{0}`")]
20 InvalidPathError(String),
21
22 #[error("attempted to spread a type that differs from its containing type at `{0}`")]
23 InvalidSpreadError(String),
24
25 #[error("attempted to interpolate a non-string type into a string at `{0}`")]
26 InvalidInterpolationError(String),
27
28 #[error("failed to deserialize input: {0}")]
29 DeserializationError(String),
30}
31
32impl serde::de::Error for Error {
33 fn custom<T>(msg: T) -> Self
34 where
35 T: Display,
36 {
37 Error::DeserializationError(msg.to_string())
38 }
39}