systemprompt_analytics/
error.rs1use 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("Analytics event store failed: {0}")]
16 EventStore(#[from] systemprompt_traits::RepositoryError),
17
18 #[error("Session not found: {0}")]
19 SessionNotFound(String),
20
21 #[error("Invalid fingerprint hash: {0}")]
22 InvalidFingerprint(String),
23
24 #[error("Missing field: {0}")]
25 MissingField(String),
26
27 #[error("Invalid argument: {0}")]
28 InvalidArgument(String),
29
30 #[error("Session expired")]
31 SessionExpired,
32
33 #[error("Behavioral bot detected: {0}")]
34 BehavioralBotDetected(String),
35
36 #[error("Anomaly detection failed: {0}")]
37 AnomalyDetectionFailed(String),
38 }
39}
40
41impl From<sqlx::Error> for AnalyticsError {
42 fn from(err: sqlx::Error) -> Self {
43 Self::Repository(systemprompt_database::RepositoryError::from(err))
44 }
45}
46
47impl AnalyticsError {
48 pub fn missing_field<T: std::fmt::Display>(field: T) -> Self {
49 Self::MissingField(field.to_string())
50 }
51
52 pub fn invalid_argument<T: Into<String>>(message: T) -> Self {
53 Self::InvalidArgument(message.into())
54 }
55}
56
57pub type Result<T> = std::result::Result<T, AnalyticsError>;