Skip to main content

inference_engine/reasoning/source/
error.rs

1use super::super::{
2    DatatypeConflictError, LiteralTypingError, OccurrenceError, OccurrenceTypingError,
3    ReasoningError, TermOccurrence,
4};
5use std::{error::Error, fmt};
6
7/// Source preparation failed; all partial scratch output must remain unpublished.
8#[derive(Debug)]
9pub enum Rdfs12SourceError<T, E> {
10    /// Shared axiom, core, constructor, storage or cancellation failure.
11    Reasoning(ReasoningError<E>),
12    /// Selected authoritative structural traversal failed.
13    Traversal(OccurrenceError<E>),
14    /// Shared source occurrence typing failed.
15    Occurrences(OccurrenceTypingError<E>),
16    /// Source literal metadata/payload/typing failed, retaining source role and path.
17    Literals(LiteralTypingError<T, E>),
18    /// Authoritative container classification failed for this exact appearance.
19    Vocabulary {
20        /// Selected root, path and exact term identity.
21        occurrence: TermOccurrence<T>,
22        /// Backend/classification/resource error.
23        error: E,
24    },
25    /// Backend returned a descriptor exceeding the explicit metadata cap.
26    VocabularyLimit,
27    /// Checked descriptor did not resolve to the selected appearing IRI identity.
28    VocabularyIdentity,
29    /// Existing triple-term decomposition did not resolve to the same exact key.
30    PropositionIdentity,
31    /// Complete source-only diagnostic scan failed.
32    Conflicts(DatatypeConflictError<E>),
33    /// Source literal semantic-diagnostic budget was exhausted.
34    DiagnosticLimit,
35    /// Outer round budget ended before proving the selected source fixpoint.
36    Rounds,
37    /// Counters cannot represent total bounded work; no wrapped report was returned.
38    CounterOverflow,
39}
40impl<T, E> From<ReasoningError<E>> for Rdfs12SourceError<T, E> {
41    fn from(error: ReasoningError<E>) -> Self {
42        Self::Reasoning(error)
43    }
44}
45impl<T, E: fmt::Display> fmt::Display for Rdfs12SourceError<T, E> {
46    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47        match self {
48            Self::Reasoning(error) => error.fmt(f),
49            Self::Traversal(error) => error.fmt(f),
50            Self::Occurrences(error) => error.fmt(f),
51            Self::Literals(error) => error.fmt(f),
52            Self::Vocabulary { error, .. } => {
53                write!(f, "source container classification failed: {error}")
54            }
55            Self::VocabularyLimit => f.write_str("source container metadata limit exceeded"),
56            Self::VocabularyIdentity => {
57                f.write_str("source container descriptor does not match selected term")
58            }
59            Self::PropositionIdentity => {
60                f.write_str("source triple-term construction does not match selected term")
61            }
62            Self::Conflicts(error) => error.fmt(f),
63            Self::DiagnosticLimit => f.write_str("source literal diagnostic limit exceeded"),
64            Self::Rounds => f.write_str("source preparation round limit exceeded"),
65            Self::CounterOverflow => f.write_str("source preparation counter capacity exceeded"),
66        }
67    }
68}
69impl<T: fmt::Debug, E: Error + 'static> Error for Rdfs12SourceError<T, E> {
70    fn source(&self) -> Option<&(dyn Error + 'static)> {
71        match self {
72            Self::Reasoning(error) => Some(error),
73            Self::Traversal(error) => Some(error),
74            Self::Occurrences(error) => Some(error),
75            Self::Literals(error) => error.source(),
76            Self::Vocabulary { error, .. } => Some(error),
77            Self::Conflicts(error) => Some(error),
78            _ => None,
79        }
80    }
81}