aquarium_control/dispatch/
messaging_error.rs

1/* Copyright 2025 Uwe Martin
2
3Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
5The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
7THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8*/
9
10//! Defines the custom error type for the Inter-Process Communication (IPC) messaging system.
11//!
12//! This module contains the `MessagingError` enum, which consolidates all potential
13//! failures that can occur within the POSIX message queue listener and command dispatcher.
14//! Using a dedicated error type allows for clear, specific, and actionable
15//! error handling throughout the IPC layer.
16//!
17//! This entire module is conditionally compiled and is only available on `target_os = "linux"`.
18//!
19//! The `MessagingError` enum is built using the `thiserror` crate.
20
21cfg_if::cfg_if! {
22    if #[cfg(target_os = "linux")] {
23        use thiserror::Error;
24        use crate::launch::channels::AquaChannelError;
25    }
26}
27
28#[cfg(target_os = "linux")]
29#[derive(Debug, Error)]
30/// Enum codifies the errors which the program may encounter in communication with the Linux messaging system.
31pub enum MessagingError {
32    /// Error occurred when trying to open POSIX message queue.
33    #[cfg(target_os = "linux")]
34    #[error("[{location}] Error occurred when trying to open POSIX message queue using message queue name {mq_name}.")]
35    PosixMessageQueueOpeningError {
36        location: String,
37        mq_name: String,
38        #[source]
39        source: std::io::Error,
40    },
41
42    /// Error occurred when trying to access POSIX message queue attributes.
43    #[cfg(target_os = "linux")]
44    #[error("[{location}] Error occurred when trying to access POSIX message queue attributes.")]
45    PosixMessageQueueAttributesError {
46        location: String,
47        #[source]
48        source: std::io::Error,
49    },
50
51    /// Unknown domain: Internal logic error
52    #[cfg(target_os = "linux")]
53    #[error("[{0}] Internal error: Domain {1} is unknown.")]
54    UnknownDomain(String, i32),
55
56    /// Error occurred when trying to send the message via the channel
57    #[cfg(target_os = "linux")]
58    #[error("[{location}] Error occurred when trying send message via channel.")]
59    ChannelSendError {
60        location: String,
61        #[source]
62        source: AquaChannelError,
63    },
64}