use thiserror::Error;
use tensorlogic_infer::beam_search::BeamSearchError;
#[derive(Debug, Error)]
pub enum RuleGuidedError {
#[error("rule-guided decoder compilation error: {0}")]
CompilationError(String),
#[error("rule-guided decoder configuration error: {0}")]
InvalidConfig(String),
#[error("beam search failure: {0}")]
BeamSearch(#[from] BeamSearchError),
#[error("logits row width mismatch: expected {expected}, got {got}")]
LogitsWidthMismatch { expected: usize, got: usize },
}
pub type RuleGuidedResult<T> = Result<T, RuleGuidedError>;
impl From<RuleGuidedError> for crate::error::TrustformerError {
fn from(err: RuleGuidedError) -> Self {
crate::error::TrustformerError::CompilationError(err.to_string())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn display_contains_context() {
let err = RuleGuidedError::InvalidConfig("lambda must be non-negative".into());
let msg = err.to_string();
assert!(msg.contains("lambda"));
assert!(msg.contains("configuration"));
}
#[test]
fn bridges_into_trustformer_error() {
let err = RuleGuidedError::CompilationError("oops".into());
let bridged: crate::error::TrustformerError = err.into();
assert!(bridged.to_string().contains("oops"));
}
}