ontologos_core/error.rs
1use thiserror::Error;
2
3use crate::entity::{EntityId, EntityKind};
4
5/// Result type alias using [`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("ontology file parsing is not available on ontologos-core; use ontologos_parser::load_ontology")]
40 ParseNotAvailable,
41 /// OWL file parse error from `ontologos-parser`.
42 #[error("parse error: {0}")]
43 Parse(String),
44 /// Serialization or deserialization failed (bad JSON, limits, format version).
45 #[error("serialization error: {0}")]
46 Serialization(String),
47 /// Ontology not loaded (reasoner).
48 #[error("ontology not loaded")]
49 OntologyNotLoaded,
50 /// Reasoning not yet implemented for the selected engine or profile.
51 #[error("reasoning not yet implemented")]
52 NotImplemented,
53 /// Generic configuration or validation error.
54 #[error("{0}")]
55 Message(String),
56}