Skip to main content

persona_wire_core/domain/
error.rs

1//! Error types layered by responsibility.
2//!
3//! - [`DomainError`] — pure domain failures (invalid entity construction,
4//!   constraint violations, unresolved references). Step C carry: every
5//!   `domain::entity::*` constructor returns `Result<_, DomainError>`.
6//! - [`WireError`] — top-level facade that wraps `DomainError` via `From`
7//!   plus residual infrastructure / catch-all variants (`Storage` / `Other`).
8//!   Application + Infrastructure layers may surface either layer's error.
9//!
10//! Future split (Application / Infrastructure dedicated enums) is carry —
11//! current scope keeps `Storage` / `Other` flat under `WireError`.
12
13use thiserror::Error;
14
15#[derive(Debug, Error)]
16pub enum DomainError {
17    #[error("invalid persona id: {0}")]
18    InvalidPersonaId(String),
19
20    #[error("invalid source uri: {0}")]
21    InvalidSource(String),
22
23    #[error("invalid specification: {0}")]
24    InvalidSpec(String),
25
26    #[error("invalid projection: {0}")]
27    InvalidProjection(String),
28
29    #[error("invalid target_form: {0}")]
30    InvalidTargetForm(String),
31
32    #[error("invalid metadata: {0}")]
33    InvalidMetadata(String),
34
35    #[error("constraint violation: {0}")]
36    ConstraintViolation(String),
37
38    #[error("type not registered: {0}")]
39    UnknownType(String),
40
41    #[error("not found: {0}")]
42    NotFound(String),
43}
44
45#[derive(Debug, Error)]
46pub enum WireError {
47    #[error(transparent)]
48    Domain(#[from] DomainError),
49
50    #[error("storage error: {0}")]
51    Storage(String),
52
53    #[error("ambiguous name '{name}': resolves to {count} rows — specify by ULID")]
54    AmbiguousName { name: String, count: usize },
55
56    #[error("other: {0}")]
57    Other(String),
58}
59
60pub type WireResult<T> = Result<T, WireError>;