systemprompt_logging/models/
log_error.rs1#[derive(Debug, thiserror::Error)]
2pub enum LoggingError {
3 #[error("Invalid log entry: {field} {reason}")]
4 InvalidLogEntry { field: String, reason: String },
5
6 #[error("Log entry validation failed: {message}")]
7 ValidationError { message: String },
8
9 #[error("Invalid log level: {level}")]
10 InvalidLogLevel { level: String },
11
12 #[error("Log entry not found: {id}")]
13 LogEntryNotFound { id: String },
14
15 #[error("Empty log module name")]
16 EmptyModuleName,
17
18 #[error("Empty log message")]
19 EmptyMessage,
20
21 #[error("Invalid metadata format")]
22 InvalidMetadata,
23
24 #[error("Database operation failed")]
25 DatabaseError(#[from] sqlx::Error),
26
27 #[error("Repository operation failed: {0}")]
28 Repository(#[from] systemprompt_database::RepositoryError),
29
30 #[error("JSON serialization failed")]
31 JsonError(#[from] serde_json::Error),
32
33 #[error("UUID generation failed")]
34 UuidError(#[from] uuid::Error),
35
36 #[error("DateTime parsing failed")]
37 DateTimeError(#[from] chrono::ParseError),
38
39 #[error("Log repository operation failed: {operation}")]
40 RepositoryError { operation: String },
41
42 #[error("Cleanup operation failed: deleted {count} entries")]
43 CleanupError { count: u64 },
44
45 #[error("Pagination parameters invalid: page={page}, per_page={per_page}")]
46 PaginationError { page: i32, per_page: i32 },
47
48 #[error("Log filter invalid: {filter_type}={value}")]
49 FilterError { filter_type: String, value: String },
50
51 #[error("Terminal output failed")]
52 TerminalError,
53
54 #[error("Database connection not available")]
55 DatabaseUnavailable,
56
57 #[error("Database pool unavailable: {0}")]
58 PoolUnavailable(String),
59
60 #[error("Retention scheduler error")]
61 Scheduler(#[from] tokio_cron_scheduler::JobSchedulerError),
62
63 #[error("No task found matching: {partial_id}")]
64 TaskNotFound { partial_id: String },
65
66 #[error("Required column `{column}` missing or invalid in row")]
67 MissingColumn { column: String },
68
69 #[error("Interactive prompt failed")]
70 #[cfg(feature = "cli")]
71 Prompt(#[from] dialoguer::Error),
72}
73
74impl LoggingError {
75 pub fn invalid_log_entry(field: impl Into<String>, reason: impl Into<String>) -> Self {
76 Self::InvalidLogEntry {
77 field: field.into(),
78 reason: reason.into(),
79 }
80 }
81
82 pub fn validation_error(message: impl Into<String>) -> Self {
83 Self::ValidationError {
84 message: message.into(),
85 }
86 }
87
88 pub fn invalid_log_level(level: impl Into<String>) -> Self {
89 Self::InvalidLogLevel {
90 level: level.into(),
91 }
92 }
93
94 pub fn log_entry_not_found(id: impl Into<String>) -> Self {
95 Self::LogEntryNotFound { id: id.into() }
96 }
97
98 pub fn repository_error(operation: impl Into<String>) -> Self {
99 Self::RepositoryError {
100 operation: operation.into(),
101 }
102 }
103
104 pub const fn cleanup_error(count: u64) -> Self {
105 Self::CleanupError { count }
106 }
107
108 pub const fn pagination_error(page: i32, per_page: i32) -> Self {
109 Self::PaginationError { page, per_page }
110 }
111
112 pub fn filter_error(filter_type: impl Into<String>, value: impl Into<String>) -> Self {
113 Self::FilterError {
114 filter_type: filter_type.into(),
115 value: value.into(),
116 }
117 }
118
119 pub fn into_sqlx_error(self) -> sqlx::Error {
120 sqlx::Error::Protocol(format!("{self}"))
121 }
122}