spatial_narrative/
error.rs1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Error, Debug)]
10pub enum Error {
11 #[error("invalid latitude {0}: must be between -90 and 90")]
13 InvalidLatitude(f64),
14
15 #[error("invalid longitude {0}: must be between -180 and 180")]
17 InvalidLongitude(f64),
18
19 #[error("invalid coordinates: lat={lat}, lon={lon}")]
21 InvalidCoordinates { lat: f64, lon: f64 },
22
23 #[error("invalid timestamp: {0}")]
25 InvalidTimestamp(String),
26
27 #[error("missing required field: {0}")]
29 MissingField(&'static str),
30
31 #[error("event not found: {0}")]
33 EventNotFound(String),
34
35 #[error("narrative not found: {0}")]
37 NarrativeNotFound(String),
38
39 #[error("I/O error: {0}")]
41 Io(#[from] std::io::Error),
42
43 #[error("JSON error: {0}")]
45 Json(#[from] serde_json::Error),
46
47 #[error("CSV error: {0}")]
49 Csv(#[from] csv::Error),
50
51 #[error("invalid format: {0}")]
53 InvalidFormat(String),
54
55 #[error("index error: {0}")]
57 IndexError(String),
58
59 #[error("graph error: {0}")]
61 GraphError(String),
62
63 #[error("analysis error: {0}")]
65 AnalysisError(String),
66
67 #[error("parse error: {0}")]
69 ParseError(String),
70
71 #[error("{context}: {source}")]
73 WithContext {
74 context: String,
75 #[source]
76 source: Box<Error>,
77 },
78}
79
80impl Error {
81 pub fn with_context(self, context: impl Into<String>) -> Self {
83 Error::WithContext {
84 context: context.into(),
85 source: Box::new(self),
86 }
87 }
88}