use evidentsource_core::domain::{ConstraintError, IdentifierError};
use thiserror::Error;
#[derive(Error, Debug, Clone)]
pub enum ConversionError {
#[error("missing required field '{field}' in {message_type}")]
MissingField {
message_type: &'static str,
field: &'static str,
},
#[error("missing oneof variant '{oneof_name}' in {message_type}")]
MissingOneof {
message_type: &'static str,
oneof_name: &'static str,
},
#[error("invalid identifier: {0}")]
InvalidIdentifier(#[from] IdentifierError),
#[error("invalid constraint: {0}")]
InvalidConstraint(#[from] ConstraintError),
#[error("nested conversion error in {context}: {source}")]
Nested {
context: &'static str,
#[source]
source: Box<ConversionError>,
},
#[error("unknown enum variant {value} for {enum_name}")]
UnknownEnumVariant { enum_name: &'static str, value: i32 },
#[error("invalid range: min ({min}) > max ({max})")]
InvalidRange { min: u64, max: u64 },
#[error("invalid timestamp")]
InvalidTimestamp,
}
impl ConversionError {
pub fn missing_field(message_type: &'static str, field: &'static str) -> Self {
ConversionError::MissingField {
message_type,
field,
}
}
pub fn missing_oneof(message_type: &'static str, oneof_name: &'static str) -> Self {
ConversionError::MissingOneof {
message_type,
oneof_name,
}
}
pub fn nested(context: &'static str, source: ConversionError) -> Self {
ConversionError::Nested {
context,
source: Box::new(source),
}
}
}