Skip to main content

remodel_core/
error.rs

1//! Error types returned by RemodelCore.
2//!
3//! All fallible operations return [`Result<T>`], an alias for
4//! `std::result::Result<T, Error>`. Errors are intentionally categorized so
5//! callers can react to specific failure modes (e.g. surface a validation
6//! issue to the user vs. abort the whole conversion).
7
8use thiserror::Error;
9
10/// Result alias used throughout the crate.
11pub type Result<T> = std::result::Result<T, Error>;
12
13/// Top-level error type for RemodelCore operations.
14#[derive(Debug, Error)]
15pub enum Error {
16    /// A reference (entity, attribute, table, …) does not exist in the model.
17    #[error("unknown {kind} `{id}`")]
18    UnknownReference {
19        /// Kind of element that was missing (e.g. `"entity"`).
20        kind: &'static str,
21        /// Stringified identifier the lookup was attempted with.
22        id: String,
23    },
24
25    /// A relationship does not have enough endpoints to be meaningful.
26    #[error("relationship `{name}` has {found} endpoint(s); at least 2 required")]
27    InsufficientEndpoints {
28        /// Relationship name as it appears in the model.
29        name: String,
30        /// Number of endpoints actually attached.
31        found: usize,
32    },
33
34    /// A specialization is malformed (no parent, no children, or cycle).
35    #[error("invalid specialization: {0}")]
36    InvalidSpecialization(String),
37
38    /// The model failed structural validation prior to a transform.
39    #[error("model validation failed with {0} error(s)")]
40    Validation(usize),
41
42    /// Conversion was aborted by the caller (e.g. a user rejected a strategy).
43    #[error("conversion cancelled")]
44    Cancelled,
45
46    /// Catch-all for unexpected internal invariants.
47    #[error("internal error: {0}")]
48    Internal(String),
49}