Skip to main content

systemprompt_analytics/
error.rs

1//! Typed error boundary for the `systemprompt-analytics` 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 AnalyticsError {
10        common: [repository, io, json],
11
12        #[error("session owner: {0}")]
13        SessionOwner(#[from] systemprompt_traits::AnalyticsProviderError),
14
15        #[error("Invalid argument: {0}")]
16        InvalidArgument(String),
17
18        #[error("Session expired")]
19        SessionExpired,
20    }
21}
22
23impl From<sqlx::Error> for AnalyticsError {
24    fn from(err: sqlx::Error) -> Self {
25        Self::Repository(systemprompt_traits::RepositoryError::from(err))
26    }
27}
28
29impl AnalyticsError {
30    pub fn invalid_argument<T: Into<String>>(message: T) -> Self {
31        Self::InvalidArgument(message.into())
32    }
33}
34
35pub type Result<T> = std::result::Result<T, AnalyticsError>;