Skip to main content

ant_types/
error.rs

1//! Domain-layer error type shared by every record plane.
2
3use thiserror::Error;
4
5/// Errors raised by the core domain layer.
6///
7/// Consumers may map these to HTTP statuses.
8#[derive(Debug, Error)]
9pub enum CoreError {
10    /// A required configuration field is absent.
11    #[error("invalid config: missing required field `{field}`")]
12    MissingConfigField {
13        /// Name of the missing field.
14        field: String,
15    },
16
17    /// A configuration field has the wrong JSON type.
18    #[error("invalid config: field `{field}` has wrong type")]
19    WrongConfigType {
20        /// Name of the mistyped field.
21        field: String,
22    },
23
24    /// No project exists with the given id.
25    #[error("project not found: id={0:?}")]
26    ProjectNotFound(crate::ProjectId),
27
28    /// A project already claims the given namespace.
29    #[error("project namespace already exists: {0}")]
30    NamespaceConflict(String),
31
32    /// The input failed validation; the message says why.
33    #[error("invalid input: {0}")]
34    InvalidInput(String),
35
36    /// Append-only resource (typically Observation) was re-submitted with
37    /// the same id but different content. Mapped to HTTP 409.
38    #[error("conflict: {0}")]
39    Conflict(String),
40
41    /// No (or invalid) authentication credentials were presented.
42    /// Mapped to HTTP 401 Unauthorized.
43    #[error("unauthorized: {0}")]
44    Unauthorized(String),
45
46    /// Caller is authenticated but lacks the required scope or
47    /// tenant binding for the action. Mapped to HTTP 403 Forbidden.
48    #[error("forbidden: {0}")]
49    Forbidden(String),
50}