Skip to main content

inference_engine/reasoning/context/
error.rs

1use super::super::{
2    LiteralTypingError, OccurrenceError, OccurrenceTypingError, Rdfs12SourceError, ReasoningError,
3    TermOccurrence,
4};
5use std::{error::Error, fmt};
6
7/// Failed source/context attempt; discard all partially staged context output.
8#[derive(Debug)]
9pub enum Rdfs12ContextError<T, E> {
10    /// Source preparation or its complete supported diagnostic phase failed.
11    Source(Rdfs12SourceError<T, E>),
12    /// Target seeding/core compilation, storage, cancellation or output budget failed.
13    Reasoning(ReasoningError<E>),
14    /// Original target traversal, decomposition or traversal budget failed.
15    Traversal(OccurrenceError<E>),
16    /// Target resource-typing phase failed.
17    Occurrences(OccurrenceTypingError<E>),
18    /// Target literal inspection failed, preserving its role, root and path.
19    Literals(LiteralTypingError<T, E>),
20    /// Authoritative container metadata lookup failed for this target appearance.
21    Vocabulary {
22        /// Exact selected original target root, path and term.
23        occurrence: TermOccurrence<T>,
24        /// Backend metadata/access/resource error.
25        error: E,
26    },
27    /// Target container descriptor exceeded the explicit metadata cap.
28    VocabularyLimit,
29    /// Target container descriptor did not resolve to the selected exact term key.
30    VocabularyIdentity,
31    /// Total counters exceeded representable capacity; no success was returned.
32    CounterOverflow,
33}
34impl<T, E> From<ReasoningError<E>> for Rdfs12ContextError<T, E> {
35    fn from(error: ReasoningError<E>) -> Self {
36        Self::Reasoning(error)
37    }
38}
39impl<T, E: fmt::Display> fmt::Display for Rdfs12ContextError<T, E> {
40    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41        match self {
42            Self::Source(error) => error.fmt(f),
43            Self::Reasoning(error) => error.fmt(f),
44            Self::Traversal(error) => error.fmt(f),
45            Self::Occurrences(error) => error.fmt(f),
46            Self::Literals(error) => error.fmt(f),
47            Self::Vocabulary { error, .. } => {
48                write!(f, "target container classification failed: {error}")
49            }
50            Self::VocabularyLimit => f.write_str("target container metadata limit exceeded"),
51            Self::VocabularyIdentity => {
52                f.write_str("target container descriptor does not match selected term")
53            }
54            Self::CounterOverflow => f.write_str("target-context counter capacity exceeded"),
55        }
56    }
57}
58impl<T: fmt::Debug, E: Error + 'static> Error for Rdfs12ContextError<T, E> {
59    fn source(&self) -> Option<&(dyn Error + 'static)> {
60        match self {
61            Self::Source(error) => error.source(),
62            Self::Reasoning(error) => Some(error),
63            Self::Traversal(error) => Some(error),
64            Self::Occurrences(error) => Some(error),
65            Self::Literals(error) => error.source(),
66            Self::Vocabulary { error, .. } => Some(error),
67            _ => None,
68        }
69    }
70}