use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("invalid latitude {0}: must be between -90 and 90")]
InvalidLatitude(f64),
#[error("invalid longitude {0}: must be between -180 and 180")]
InvalidLongitude(f64),
#[error("invalid coordinates: lat={lat}, lon={lon}")]
InvalidCoordinates { lat: f64, lon: f64 },
#[error("invalid timestamp: {0}")]
InvalidTimestamp(String),
#[error("missing required field: {0}")]
MissingField(&'static str),
#[error("event not found: {0}")]
EventNotFound(String),
#[error("narrative not found: {0}")]
NarrativeNotFound(String),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("CSV error: {0}")]
Csv(#[from] csv::Error),
#[error("invalid format: {0}")]
InvalidFormat(String),
#[error("index error: {0}")]
IndexError(String),
#[error("graph error: {0}")]
GraphError(String),
#[error("analysis error: {0}")]
AnalysisError(String),
#[error("parse error: {0}")]
ParseError(String),
#[error("{context}: {source}")]
WithContext {
context: String,
#[source]
source: Box<Error>,
},
}
impl Error {
pub fn with_context(self, context: impl Into<String>) -> Self {
Error::WithContext {
context: context.into(),
source: Box::new(self),
}
}
}