use super::super::{
LiteralTypingError, OccurrenceError, OccurrenceTypingError, Rdfs12SourceError, ReasoningError,
TermOccurrence,
};
use std::{error::Error, fmt};
#[derive(Debug)]
pub enum Rdfs12ContextError<T, E> {
Source(Rdfs12SourceError<T, E>),
Reasoning(ReasoningError<E>),
Traversal(OccurrenceError<E>),
Occurrences(OccurrenceTypingError<E>),
Literals(LiteralTypingError<T, E>),
Vocabulary {
occurrence: TermOccurrence<T>,
error: E,
},
VocabularyLimit,
VocabularyIdentity,
CounterOverflow,
}
impl<T, E> From<ReasoningError<E>> for Rdfs12ContextError<T, E> {
fn from(error: ReasoningError<E>) -> Self {
Self::Reasoning(error)
}
}
impl<T, E: fmt::Display> fmt::Display for Rdfs12ContextError<T, E> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Source(error) => error.fmt(f),
Self::Reasoning(error) => error.fmt(f),
Self::Traversal(error) => error.fmt(f),
Self::Occurrences(error) => error.fmt(f),
Self::Literals(error) => error.fmt(f),
Self::Vocabulary { error, .. } => {
write!(f, "target container classification failed: {error}")
}
Self::VocabularyLimit => f.write_str("target container metadata limit exceeded"),
Self::VocabularyIdentity => {
f.write_str("target container descriptor does not match selected term")
}
Self::CounterOverflow => f.write_str("target-context counter capacity exceeded"),
}
}
}
impl<T: fmt::Debug, E: Error + 'static> Error for Rdfs12ContextError<T, E> {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Source(error) => error.source(),
Self::Reasoning(error) => Some(error),
Self::Traversal(error) => Some(error),
Self::Occurrences(error) => Some(error),
Self::Literals(error) => error.source(),
Self::Vocabulary { error, .. } => Some(error),
_ => None,
}
}
}