1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use std::fmt::{Debug, Display};
use thiserror::Error;

use crate::Rule;

pub type Result<T> = std::result::Result<T, Error>;

#[derive(Error, Debug)]
pub enum Error {
    #[error(transparent)]
    Io(#[from] std::io::Error),

    #[error(transparent)]
    ParserError(#[from] Box<pest::error::Error<Rule>>),

    #[error("failed to resolve referenced input `{0}`")]
    InputResolveError(String),

    #[error("attempted to use dot-notation on non-object value at `{0}`")]
    InvalidPathError(String),

    #[error("attempted to spread a type that differs from its containing type at `{0}`")]
    InvalidSpreadError(String),

    #[error("attempted to interpolate a non-string type into a string at `{0}`")]
    InvalidInterpolationError(String),

    #[error("failed to deserialize input: {0}")]
    DeserializationError(String),
}

impl serde::de::Error for Error {
    fn custom<T>(msg: T) -> Self
    where
        T: Display,
    {
        Error::DeserializationError(msg.to_string())
    }
}