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("JSON serialization failed")]
28 JsonError(#[from] serde_json::Error),
29
30 #[error("UUID generation failed")]
31 UuidError(#[from] uuid::Error),
32
33 #[error("DateTime parsing failed")]
34 DateTimeError(#[from] chrono::ParseError),
35
36 #[error("Log repository operation failed: {operation}")]
37 RepositoryError { operation: String },
38
39 #[error("Cleanup operation failed: deleted {count} entries")]
40 CleanupError { count: u64 },
41
42 #[error("Pagination parameters invalid: page={page}, per_page={per_page}")]
43 PaginationError { page: i32, per_page: i32 },
44
45 #[error("Log filter invalid: {filter_type}={value}")]
46 FilterError { filter_type: String, value: String },
47
48 #[error("Terminal output failed")]
49 TerminalError,
50
51 #[error("Database connection not available")]
52 DatabaseUnavailable,
53
54 #[error("Query operation failed")]
55 QueryError(#[from] anyhow::Error),
56}
57
58impl LoggingError {
59 pub fn invalid_log_entry(field: impl Into<String>, reason: impl Into<String>) -> Self {
60 Self::InvalidLogEntry {
61 field: field.into(),
62 reason: reason.into(),
63 }
64 }
65
66 pub fn validation_error(message: impl Into<String>) -> Self {
67 Self::ValidationError {
68 message: message.into(),
69 }
70 }
71
72 pub fn invalid_log_level(level: impl Into<String>) -> Self {
73 Self::InvalidLogLevel {
74 level: level.into(),
75 }
76 }
77
78 pub fn log_entry_not_found(id: impl Into<String>) -> Self {
79 Self::LogEntryNotFound { id: id.into() }
80 }
81
82 pub fn repository_error(operation: impl Into<String>) -> Self {
83 Self::RepositoryError {
84 operation: operation.into(),
85 }
86 }
87
88 pub const fn cleanup_error(count: u64) -> Self {
89 Self::CleanupError { count }
90 }
91
92 pub const fn pagination_error(page: i32, per_page: i32) -> Self {
93 Self::PaginationError { page, per_page }
94 }
95
96 pub fn filter_error(filter_type: impl Into<String>, value: impl Into<String>) -> Self {
97 Self::FilterError {
98 filter_type: filter_type.into(),
99 value: value.into(),
100 }
101 }
102
103 pub fn into_sqlx_error(self) -> sqlx::Error {
104 sqlx::Error::Protocol(format!("{self}"))
105 }
106}