Common System 0.2.0
Common interfaces and patterns for system integration
Loading...
Searching...
No Matches
error.cppm
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
27module;
28
29#include <string>
30#include <string_view>
31
32export module kcenon.common:error;
33
34export namespace kcenon::common::error {
35
40enum class category : int {
41 success = 0,
42 common = -1,
43 thread_system = -100,
44 logger_system = -200,
45 monitoring_system = -300,
46 container_system = -400,
47 database_system = -500,
48 network_system = -600,
49 pacs_system = -700,
50};
51
56namespace codes {
57
58// ============================================================================
59// Common Error Codes (-1 to -99)
60// ============================================================================
61namespace common_errors {
62 constexpr int success = 0;
63 constexpr int invalid_argument = -1;
64 constexpr int not_found = -2;
65 constexpr int permission_denied = -3;
66 constexpr int timeout = -4;
67 constexpr int cancelled = -5;
68 constexpr int not_initialized = -6;
69 constexpr int already_exists = -7;
70 constexpr int out_of_memory = -8;
71 constexpr int io_error = -9;
72 constexpr int network_error = -10;
73 constexpr int registry_frozen = -11;
74 constexpr int internal_error = -99;
75} // namespace common_errors
76
77// ============================================================================
78// thread_system Error Codes (-100 to -199)
79// ============================================================================
80namespace thread_system {
81 constexpr int base = static_cast<int>(category::thread_system);
82
83 // Pool errors (-100 to -119)
84 constexpr int pool_full = base - 0;
85 constexpr int pool_shutdown = base - 1;
86 constexpr int pool_not_started = base - 2;
87 constexpr int invalid_pool_size = base - 3;
88
89 // Worker errors (-120 to -139)
90 constexpr int worker_failed = base - 20;
91 constexpr int worker_not_found = base - 21;
92 constexpr int worker_busy = base - 22;
93
94 // Job errors (-140 to -159)
95 constexpr int job_rejected = base - 40;
96 constexpr int job_timeout = base - 41;
97 constexpr int job_cancelled = base - 42;
98 constexpr int invalid_job = base - 43;
99
100 // Queue errors (-160 to -179)
101 constexpr int queue_full = base - 60;
102 constexpr int queue_empty = base - 61;
103 constexpr int queue_stopped = base - 62;
104} // namespace thread_system
105
106// ============================================================================
107// logger_system Error Codes (-200 to -299)
108// ============================================================================
109namespace logger_system {
110 constexpr int base = static_cast<int>(category::logger_system);
111
112 // File errors (-200 to -219)
113 constexpr int file_open_failed = base - 0;
114 constexpr int file_write_failed = base - 1;
115 constexpr int file_close_failed = base - 2;
116 constexpr int file_rotation_failed = base - 3;
117 constexpr int file_permission_denied = base - 4;
118
119 // Writer errors (-220 to -239)
120 constexpr int writer_not_initialized = base - 20;
121 constexpr int writer_stopped = base - 21;
122 constexpr int writer_full = base - 22;
123 constexpr int async_writer_failed = base - 23;
124
125 // Format errors (-240 to -259)
126 constexpr int invalid_format = base - 40;
127 constexpr int format_error = base - 41;
128
129 // Filter errors (-260 to -279)
130 constexpr int invalid_filter = base - 60;
131 constexpr int filter_rejected = base - 61;
132} // namespace logger_system
133
134// ============================================================================
135// monitoring_system Error Codes (-300 to -399)
136// ============================================================================
137namespace monitoring_system {
138 constexpr int base = static_cast<int>(category::monitoring_system);
139
140 // Metric errors (-300 to -319)
141 constexpr int metric_not_found = base - 0;
142 constexpr int invalid_metric_type = base - 1;
143 constexpr int metric_collection_failed = base - 2;
144
145 // Storage errors (-320 to -339)
146 constexpr int storage_full = base - 20;
147 constexpr int storage_error = base - 21;
148
149 // Event errors (-340 to -359)
150 constexpr int event_publish_failed = base - 40;
151 constexpr int event_subscribe_failed = base - 41;
152 constexpr int invalid_event_type = base - 42;
153
154 // Profiler errors (-360 to -379)
155 constexpr int profiler_not_enabled = base - 60;
156 constexpr int profiler_error = base - 61;
157} // namespace monitoring_system
158
159// ============================================================================
160// container_system Error Codes (-400 to -499)
161// ============================================================================
162namespace container_system {
163 constexpr int base = static_cast<int>(category::container_system);
164
165 // Value errors (-400 to -419)
166 constexpr int value_type_mismatch = base - 0;
167 constexpr int invalid_value_type = base - 1;
168 constexpr int value_conversion_failed = base - 2;
169
170 // Serialization errors (-420 to -439)
171 constexpr int serialization_failed = base - 20;
172 constexpr int deserialization_failed = base - 21;
173 constexpr int invalid_format = base - 22;
174
175 // Memory pool errors (-440 to -459)
176 constexpr int pool_exhausted = base - 40;
177 constexpr int allocation_failed = base - 41;
178 constexpr int invalid_allocation_size = base - 42;
179
180 // Container errors (-460 to -479)
181 constexpr int key_not_found = base - 60;
182 constexpr int duplicate_key = base - 61;
183 constexpr int container_full = base - 62;
184} // namespace container_system
185
186// ============================================================================
187// database_system Error Codes (-500 to -599)
188// ============================================================================
189namespace database_system {
190 constexpr int base = static_cast<int>(category::database_system);
191
192 // Connection errors (-500 to -519)
193 constexpr int connection_failed = base - 0;
194 constexpr int connection_lost = base - 1;
195 constexpr int connection_timeout = base - 2;
196 constexpr int invalid_connection_string = base - 3;
197
198 // Pool errors (-520 to -539)
199 constexpr int pool_exhausted = base - 20;
200 constexpr int pool_shutdown = base - 21;
201 constexpr int pool_timeout = base - 22;
202
203 // Query errors (-540 to -559)
204 constexpr int query_failed = base - 40;
205 constexpr int query_syntax_error = base - 41;
206 constexpr int query_timeout = base - 42;
207
208 // Transaction errors (-560 to -579)
209 constexpr int transaction_failed = base - 60;
210 constexpr int transaction_rolled_back = base - 61;
211 constexpr int transaction_timeout = base - 62;
212} // namespace database_system
213
214// ============================================================================
215// network_system Error Codes (-600 to -699)
216// ============================================================================
217namespace network_system {
218 constexpr int base = static_cast<int>(category::network_system);
219
220 // Connection errors (-600 to -619)
221 constexpr int connection_failed = base - 0;
222 constexpr int connection_refused = base - 1;
223 constexpr int connection_timeout = base - 2;
224 constexpr int connection_closed = base - 3;
225
226 // Session errors (-620 to -639)
227 constexpr int session_not_found = base - 20;
228 constexpr int session_expired = base - 21;
229 constexpr int invalid_session = base - 22;
230
231 // Send/Receive errors (-640 to -659)
232 constexpr int send_failed = base - 40;
233 constexpr int receive_failed = base - 41;
234 constexpr int message_too_large = base - 42;
235
236 // Server errors (-660 to -679)
237 constexpr int server_not_started = base - 60;
238 constexpr int server_already_running = base - 61;
239 constexpr int bind_failed = base - 62;
240} // namespace network_system
241
242// ============================================================================
243// pacs_system Error Codes (-700 to -799)
244// ============================================================================
245namespace pacs_system {
246 constexpr int base = static_cast<int>(category::pacs_system);
247
248 // DICOM file errors (-700 to -719)
249 constexpr int file_not_found = base - 0;
250 constexpr int file_read_error = base - 1;
251 constexpr int file_write_error = base - 2;
252 constexpr int invalid_dicom_file = base - 3;
253 constexpr int missing_dicm_prefix = base - 4;
254 constexpr int invalid_meta_info = base - 5;
255 constexpr int missing_transfer_syntax = base - 6;
256 constexpr int unsupported_transfer_syntax = base - 7;
257
258 // DICOM element errors (-720 to -739)
259 constexpr int element_not_found = base - 20;
260 constexpr int value_conversion_error = base - 21;
261 constexpr int invalid_vr = base - 22;
262 constexpr int invalid_tag = base - 23;
263 constexpr int data_size_mismatch = base - 24;
264
265 // Encoding/Decoding errors (-740 to -759)
266 constexpr int decode_error = base - 40;
267 constexpr int encode_error = base - 41;
268 constexpr int compression_error = base - 42;
269 constexpr int decompression_error = base - 43;
270
271 // Network/Association errors (-760 to -779)
272 constexpr int association_rejected = base - 60;
273 constexpr int association_aborted = base - 61;
274 constexpr int dimse_error = base - 62;
275 constexpr int pdu_error = base - 63;
276
277 // Storage errors (-780 to -799)
278 constexpr int storage_failed = base - 80;
279 constexpr int retrieve_failed = base - 81;
280 constexpr int query_failed = base - 82;
281} // namespace pacs_system
282
283} // namespace codes
284
290inline std::string_view get_error_message(int code) {
291 switch (code) {
292 // Common errors
293 case codes::common_errors::success: return "Success";
294 case codes::common_errors::invalid_argument: return "Invalid argument";
295 case codes::common_errors::not_found: return "Not found";
296 case codes::common_errors::permission_denied: return "Permission denied";
297 case codes::common_errors::timeout: return "Timeout";
298 case codes::common_errors::cancelled: return "Cancelled";
299 case codes::common_errors::not_initialized: return "Not initialized";
300 case codes::common_errors::already_exists: return "Already exists";
301 case codes::common_errors::out_of_memory: return "Out of memory";
302 case codes::common_errors::io_error: return "I/O error";
303 case codes::common_errors::network_error: return "Network error";
304 case codes::common_errors::registry_frozen: return "Registry is frozen";
305 case codes::common_errors::internal_error: return "Internal error";
306
307 // thread_system errors
308 case codes::thread_system::pool_full: return "Thread pool full";
309 case codes::thread_system::pool_shutdown: return "Thread pool shutdown";
310 case codes::thread_system::job_rejected: return "Job rejected";
311 case codes::thread_system::job_timeout: return "Job timeout";
312
313 // logger_system errors
314 case codes::logger_system::file_open_failed: return "Failed to open log file";
315 case codes::logger_system::file_write_failed: return "Failed to write to log file";
316 case codes::logger_system::file_rotation_failed: return "Log file rotation failed";
317
318 // monitoring_system errors
319 case codes::monitoring_system::metric_not_found: return "Metric not found";
320 case codes::monitoring_system::storage_full: return "Metric storage full";
321
322 // container_system errors
323 case codes::container_system::value_type_mismatch: return "Value type mismatch";
324 case codes::container_system::serialization_failed: return "Serialization failed";
325 case codes::container_system::pool_exhausted: return "Memory pool exhausted";
326
327 // database_system errors
328 case codes::database_system::connection_failed: return "Database connection failed";
329 case codes::database_system::pool_exhausted: return "Connection pool exhausted";
330 case codes::database_system::query_failed: return "Database query failed";
331
332 // network_system errors
333 case codes::network_system::connection_failed: return "Network connection failed";
334 case codes::network_system::send_failed: return "Network send failed";
335 case codes::network_system::server_not_started: return "Server not started";
336
337 // pacs_system errors
338 case codes::pacs_system::file_not_found: return "DICOM file not found";
339 case codes::pacs_system::file_read_error: return "Failed to read DICOM file";
340 case codes::pacs_system::file_write_error: return "Failed to write DICOM file";
341 case codes::pacs_system::invalid_dicom_file: return "Invalid DICOM file format";
342 case codes::pacs_system::missing_dicm_prefix: return "Missing DICM prefix";
343 case codes::pacs_system::invalid_meta_info: return "Invalid File Meta Information";
344 case codes::pacs_system::missing_transfer_syntax: return "Missing Transfer Syntax";
345 case codes::pacs_system::unsupported_transfer_syntax: return "Unsupported Transfer Syntax";
346 case codes::pacs_system::element_not_found: return "DICOM element not found";
347 case codes::pacs_system::value_conversion_error: return "Value conversion failed";
348 case codes::pacs_system::decode_error: return "DICOM decode error";
349 case codes::pacs_system::encode_error: return "DICOM encode error";
350 case codes::pacs_system::association_rejected: return "DICOM association rejected";
351 case codes::pacs_system::storage_failed: return "DICOM storage failed";
352
353 default: return "Unknown error";
354 }
355}
356
362inline std::string_view get_category_name(int code) {
363 if (code >= 0) return "Success";
364 if (code > static_cast<int>(category::thread_system)) return "Common";
365 if (code > static_cast<int>(category::logger_system)) return "ThreadSystem";
366 if (code > static_cast<int>(category::monitoring_system)) return "LoggerSystem";
367 if (code > static_cast<int>(category::container_system)) return "MonitoringSystem";
368 if (code > static_cast<int>(category::database_system)) return "ContainerSystem";
369 if (code > static_cast<int>(category::network_system)) return "DatabaseSystem";
370 if (code > static_cast<int>(category::pacs_system)) return "NetworkSystem";
371 return "PACSSystem";
372}
373
374} // namespace kcenon::common::error
Specific error codes organized by category.
std::string_view get_error_message(int code)
Get human-readable error message for error code.
category
Error code category ranges for compile-time validation.
Definition error_codes.h:37
std::string_view get_category_name(int code)
Get category name for error code.