pub mod diagnostic;
pub mod similarity;
pub use diagnostic::Diagnostic;
pub fn try_map_error(err: &anyhow::Error) -> Option<Diagnostic> {
if let Some(diag) = err.downcast_ref::<Diagnostic>() {
return Some(diag.clone());
}
let msg = err.to_string();
if msg.contains("embedding dims mismatch") || msg.contains("dimension mismatch") {
return Some(
Diagnostic::new(
diagnostic::codes::E_EMB_DIMS,
"Embedding dimensions mismatch",
)
.with_context(serde_json::json!({ "raw_error": msg }))
.with_fix_step("Run: assay trace precompute-embeddings --trace <file> ...")
.with_fix_step(
"Ensure the same embedding model is used for baseline and candidate runs",
),
);
}
if msg.contains("Baseline mismatch") || (msg.contains("baseline") && msg.contains("schema")) {
return Some(
Diagnostic::new(
diagnostic::codes::E_BASE_MISMATCH,
"Baseline incompatbile with current run",
)
.with_context(serde_json::json!({ "raw_error": msg }))
.with_fix_step("Regenerate baseline on main branch: assay ci --export-baseline ...")
.with_fix_step("Check that your config suite name matches the baseline suite"),
);
}
None
}
use std::fmt::{Display, Formatter};
#[derive(Debug)]
pub struct ConfigError(pub String);
impl Display for ConfigError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "ConfigError: {}", self.0)
}
}
impl std::error::Error for ConfigError {}