pub use decoder_value::Unexpected;
use crate::Value;
use std::collections::BTreeMap;
use std::sync::Arc;
#[allow(missing_docs)]
#[derive(Debug, Clone, thiserror::Error)]
pub enum Error {
#[error("invalid type (expected: {expected}, got: {got:?})")]
InvalidType {
expected: &'static str,
got: Unexpected,
},
#[error("missing field (key: {key}, map: {map:?})")]
FieldMissing {
key: String,
map: BTreeMap<Value, Value>,
},
#[error("custom error: {0}")]
Custom(String),
#[error("deserializer error: {0}")]
Deserializer(Arc<dyn std::error::Error + Send + Sync>),
}
impl Error {
pub fn custom(error: impl ToString) -> Self {
Self::Custom(error.to_string())
}
pub(crate) fn deserializer(error: impl std::error::Error + Send + Sync + 'static) -> Self {
Self::Deserializer(Arc::new(error))
}
}
impl From<decoder_value::DeserializerError> for Error {
fn from(error: decoder_value::DeserializerError) -> Self {
Self::Deserializer(Arc::new(error))
}
}