use std::fmt;
use serde::{Deserialize, Serialize};
pub use helios_fhir::search::errors::{LoaderError, RegistryError};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ExtractionError {
EvaluationFailed {
param_name: String,
expression: String,
error: String,
},
ConversionFailed {
param_name: String,
expected_type: String,
actual_value: String,
},
UnsupportedType {
param_name: String,
value_type: String,
},
InvalidResource {
message: String,
},
FhirPathError {
expression: String,
message: String,
},
ConversionError {
message: String,
},
}
impl fmt::Display for ExtractionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ExtractionError::EvaluationFailed {
param_name,
expression,
error,
} => {
write!(
f,
"Failed to evaluate '{}' for parameter '{}': {}",
expression, param_name, error
)
}
ExtractionError::ConversionFailed {
param_name,
expected_type,
actual_value,
} => {
write!(
f,
"Cannot convert '{}' to {} for parameter '{}'",
actual_value, expected_type, param_name
)
}
ExtractionError::UnsupportedType {
param_name,
value_type,
} => {
write!(
f,
"Unsupported value type '{}' for parameter '{}'",
value_type, param_name
)
}
ExtractionError::InvalidResource { message } => {
write!(f, "Invalid resource: {}", message)
}
ExtractionError::FhirPathError {
expression,
message,
} => {
write!(f, "FHIRPath error evaluating '{}': {}", expression, message)
}
ExtractionError::ConversionError { message } => {
write!(f, "Conversion error: {}", message)
}
}
}
}
impl std::error::Error for ExtractionError {}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ReindexError {
JobNotFound {
job_id: String,
},
AlreadyRunning {
existing_job_id: String,
},
ProcessingFailed {
resource_type: String,
resource_id: String,
error: String,
},
StorageError {
message: String,
},
Cancelled {
job_id: String,
},
}
impl fmt::Display for ReindexError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ReindexError::JobNotFound { job_id } => {
write!(f, "Reindex job '{}' not found", job_id)
}
ReindexError::AlreadyRunning { existing_job_id } => {
write!(
f,
"Reindex already running with job ID '{}'",
existing_job_id
)
}
ReindexError::ProcessingFailed {
resource_type,
resource_id,
error,
} => {
write!(
f,
"Failed to reindex {}/{}: {}",
resource_type, resource_id, error
)
}
ReindexError::StorageError { message } => {
write!(f, "Storage error during reindex: {}", message)
}
ReindexError::Cancelled { job_id } => {
write!(f, "Reindex job '{}' was cancelled", job_id)
}
}
}
}
impl std::error::Error for ReindexError {}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_extraction_error_display() {
let err = ExtractionError::EvaluationFailed {
param_name: "name".to_string(),
expression: "Patient.name".to_string(),
error: "syntax error".to_string(),
};
assert!(err.to_string().contains("name"));
assert!(err.to_string().contains("Patient.name"));
}
#[test]
fn test_reindex_error_display() {
let err = ReindexError::ProcessingFailed {
resource_type: "Patient".to_string(),
resource_id: "123".to_string(),
error: "database error".to_string(),
};
assert!(err.to_string().contains("Patient/123"));
}
}