ontologos_core/error.rs
1use thiserror::Error;
2
3use crate::entity::{EntityId, EntityKind};
4
5/// Result type alias using [`enum@Error`].
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Errors produced by the core ontology model.
9///
10/// See the [error reference](https://github.com/eddiethedean/ontologos/blob/main/docs/reference/errors.md)
11/// for recovery guidance.
12#[derive(Debug, Error, Clone, PartialEq, Eq)]
13pub enum Error {
14 /// The IRI string is not a valid absolute IRI (wrong scheme, control chars, too long).
15 ///
16 /// Use `http`, `https`, or `urn` schemes only.
17 #[error("invalid IRI: {0}")]
18 InvalidIri(String),
19 /// An entity was registered with a conflicting kind for the same IRI.
20 #[error("entity kind mismatch for {iri}: expected {expected:?}, found {found:?}")]
21 EntityKindMismatch {
22 /// Resolved IRI string for the conflicting entity.
23 iri: String,
24 /// Expected entity kind.
25 expected: EntityKind,
26 /// Found entity kind.
27 found: EntityKind,
28 },
29 /// Referenced entity id does not exist in the registry.
30 #[error("unknown entity: {0:?}")]
31 UnknownEntity(EntityId),
32 /// Axiom validation failed (wrong kinds, unknown IRI in JSON, degenerate operands).
33 #[error("invalid axiom: {0}")]
34 InvalidAxiom(String),
35 /// File parsing is not available on `ontologos-core` alone.
36 ///
37 /// Use [`Ontology::from_json`](crate::Ontology::from_json), the builder API, or
38 /// `ontologos_parser::load_ontology`.
39 #[error(
40 "ontology file parsing is not available on ontologos-core; use ontologos_parser::load_ontology"
41 )]
42 ParseNotAvailable,
43 /// OWL file parse error from `ontologos-parser`.
44 #[error("parse error: {0}")]
45 Parse(String),
46 /// Serialization or deserialization failed (bad JSON, limits, format version).
47 #[error("serialization error: {0}")]
48 Serialization(String),
49 /// Resource limit exceeded during load or reasoning.
50 #[error("resource limit exceeded: {0}")]
51 ResourceLimit(String),
52 /// Ontology not loaded (reasoner).
53 #[error("ontology not loaded")]
54 OntologyNotLoaded,
55 /// Reasoning not yet implemented for the selected engine or profile.
56 #[error("reasoning not yet implemented")]
57 NotImplemented,
58 /// Consistency check did not complete (budget or tableau limit).
59 #[error("consistency check incomplete")]
60 IncompleteConsistency,
61 /// Generic configuration or validation error.
62 #[error("{0}")]
63 Message(String),
64}