Skip to main content

serde_eure/
error.rs

1use std::fmt;
2
3use eure::document::InsertError;
4use eure::document::constructor::ScopeError;
5use eure::document::write::WriteError;
6use thiserror::Error;
7
8#[derive(Debug, Error)]
9pub enum DeError {
10    #[error("{0}")]
11    Custom(String),
12    #[error("type mismatch: expected {expected}, got {actual}")]
13    TypeMismatch {
14        expected: &'static str,
15        actual: String,
16    },
17    #[error("missing field: {0}")]
18    MissingField(String),
19    #[error("unexpected end of sequence")]
20    EndOfSequence,
21    #[error("integer out of range")]
22    IntOutOfRange,
23    #[error("no variant matched")]
24    NoVariantMatched,
25    #[error("invalid variant name: {0}")]
26    InvalidVariantName(String),
27    #[error("PartialMap unsupported in serde-eure v1")]
28    PartialMapUnsupported,
29    #[error(transparent)]
30    Write(#[from] WriteError),
31    #[error(transparent)]
32    Insert(#[from] InsertError),
33    #[error(transparent)]
34    Scope(#[from] ScopeError),
35}
36
37impl serde::de::Error for DeError {
38    fn custom<T: fmt::Display>(msg: T) -> Self {
39        Self::Custom(msg.to_string())
40    }
41}
42
43#[derive(Debug, Error)]
44pub enum SerError {
45    #[error("{0}")]
46    Custom(String),
47    #[error("missing field: {0}")]
48    MissingField(String),
49    #[error("hole node cannot be serialized")]
50    UnexpectedHole,
51    #[error("PartialMap unsupported")]
52    PartialMapUnsupported,
53    #[error("non-string map key")]
54    NonStringKey,
55    #[error("BigInt out of range for serialization")]
56    BigIntOutOfRange,
57    #[error("non-finite float")]
58    NonFiniteFloat,
59}
60
61impl serde::ser::Error for SerError {
62    fn custom<T: fmt::Display>(msg: T) -> Self {
63        Self::Custom(msg.to_string())
64    }
65}