use std::path::PathBuf;
pub type Result<T> = std::result::Result<T, TermlinkError>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum TermlinkError {
#[error("glossary file not found: {0}")]
GlossaryNotFound(PathBuf),
#[error("failed to parse [preprocessor.termlink] configuration")]
BadConfig(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
#[error("alias '{alias}' for term '{term}' conflicts with an existing term")]
AliasConflict {
alias: String,
term: String,
},
#[error("failed to re-serialize processed markdown")]
MarkdownSerialize(#[from] pulldown_cmark_to_cmark::Error),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn glossary_not_found_display_includes_path() {
let err = TermlinkError::GlossaryNotFound(PathBuf::from("reference/glossary.md"));
assert_eq!(
err.to_string(),
"glossary file not found: reference/glossary.md"
);
}
#[test]
fn alias_conflict_display_includes_both_names() {
let err = TermlinkError::AliasConflict {
alias: "RESTful".to_string(),
term: "API".to_string(),
};
let rendered = err.to_string();
assert!(rendered.contains("RESTful"));
assert!(rendered.contains("API"));
}
}