Skip to main content

systemprompt_content/
error.rs

1//! Typed error surface for the content crate.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use systemprompt_models::domain_error;
7
8domain_error! {
9    pub enum ContentError {
10        common: [repository, io, json, yaml, validation],
11
12        #[error("database must be PostgreSQL")]
13        DatabaseNotPostgres,
14
15        #[error("content not found: {0}")]
16        ContentNotFound(String),
17
18        #[error("link not found: {0}")]
19        LinkNotFound(String),
20
21        #[error("invalid request: {0}")]
22        InvalidRequest(String),
23
24        #[error("parse error: {0}")]
25        Parse(String),
26
27        #[error("invalid date '{value}'")]
28        InvalidDate {
29            value: String,
30            #[source]
31            source: chrono::ParseError,
32        },
33
34        #[error("invalid identifier: {0}")]
35        InvalidIdentifier(#[from] systemprompt_identifiers::error::IdValidationError),
36    }
37}
38
39impl From<sqlx::Error> for ContentError {
40    fn from(err: sqlx::Error) -> Self {
41        Self::Repository(systemprompt_traits::RepositoryError::from(err))
42    }
43}
44
45pub type ContentResult<T> = Result<T, ContentError>;