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 until v0.2.
36 ///
37 /// Use [`Ontology::from_json`](crate::Ontology::from_json) or the builder API instead.
38 #[error("ontology file parsing is not available until v0.2; use Ontology::from_json or the builder API")]
39 ParseNotAvailable,
40 /// Serialization or deserialization failed (bad JSON, limits, format version).
41 #[error("serialization error: {0}")]
42 Serialization(String),
43 /// Ontology not loaded (reasoner).
44 #[error("ontology not loaded")]
45 OntologyNotLoaded,
46 /// Reasoning not yet implemented for the selected engine or profile.
47 #[error("reasoning not yet implemented")]
48 NotImplemented,
49 /// Generic configuration or validation error.
50 #[error("{0}")]
51 Message(String),
52}