Skip to main content

pytorch_reader/nested/
error.rs

1/// The error type for nested-value serde.
2#[derive(thiserror::Error, Debug)]
3pub enum Error {
4    /// Failed to deserialize.
5    #[error("failed to deserialize: {0}")]
6    Deserialize(#[from] serde::de::value::Error),
7
8    /// Failed to serialize.
9    #[error("failed to serialize")]
10    Serialize(String),
11
12    /// Encountered an invalid state.
13    #[error("invalid state")]
14    InvalidState,
15
16    /// Other error.
17    #[error("other error: {0}")]
18    Other(String),
19}
20
21impl serde::de::Error for Error {
22    fn custom<T: std::fmt::Display>(msg: T) -> Self {
23        Error::Deserialize(serde::de::value::Error::custom(msg.to_string()))
24    }
25}
26
27impl serde::ser::Error for Error {
28    fn custom<T: std::fmt::Display>(msg: T) -> Self {
29        Error::Serialize(msg.to_string())
30    }
31}