2023-12-08 16:21:00 +01:00
|
|
|
//! Contains the error types used by the [`notify`](super) module.
|
|
|
|
#![allow(clippy::module_name_repetitions)]
|
|
|
|
|
2023-12-08 14:46:54 +01:00
|
|
|
use core::fmt::Display;
|
|
|
|
use std::error::Error;
|
|
|
|
|
|
|
|
use rustix::io::Errno;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2023-12-08 16:21:00 +01:00
|
|
|
pub enum NewNotifierError {
|
2023-12-08 14:46:54 +01:00
|
|
|
InvalidAbstractSocket(Errno),
|
|
|
|
InvalidSocketPath(Errno),
|
|
|
|
CouldntOpenSocket(std::io::Error),
|
2023-12-08 16:21:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for NewNotifierError {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match self {
|
|
|
|
NewNotifierError::InvalidAbstractSocket(error) => {
|
|
|
|
write!(f, "couldn't open notify abstract socket: {error}")
|
|
|
|
}
|
|
|
|
NewNotifierError::InvalidSocketPath(error) => {
|
|
|
|
write!(f, "couldn't open notify socket from path: {error}")
|
|
|
|
}
|
|
|
|
NewNotifierError::CouldntOpenSocket(error) => {
|
|
|
|
write!(f, "couldn't open unix socket: {error}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Error for NewNotifierError {
|
|
|
|
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
|
|
|
match self {
|
|
|
|
NewNotifierError::InvalidAbstractSocket(error)
|
|
|
|
| NewNotifierError::InvalidSocketPath(error) => Some(error),
|
|
|
|
NewNotifierError::CouldntOpenSocket(error) => Some(error),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum NotifyError {
|
|
|
|
SanityCheck(SanityCheckError),
|
2023-12-08 14:46:54 +01:00
|
|
|
SendMsg(Errno),
|
2023-12-08 16:21:00 +01:00
|
|
|
PushAncillaryMessage,
|
2023-12-08 14:46:54 +01:00
|
|
|
PartialSend,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<SanityCheckError> for NotifyError {
|
|
|
|
fn from(value: SanityCheckError) -> Self {
|
|
|
|
Self::SanityCheck(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-08 16:21:00 +01:00
|
|
|
impl Display for NotifyError {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match self {
|
|
|
|
NotifyError::SanityCheck(error) => {
|
|
|
|
write!(f, "NotifyState sanity check failed: {error}")
|
|
|
|
}
|
|
|
|
NotifyError::SendMsg(error) => write!(f, "couldn't send the message: {error}"),
|
|
|
|
NotifyError::PushAncillaryMessage => {
|
|
|
|
f.write_str("couldn't push necessary ancillary message for fd passing")
|
|
|
|
}
|
|
|
|
NotifyError::PartialSend => f.write_str("only some of the message could be sent"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Error for NotifyError {
|
|
|
|
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
|
|
|
match self {
|
|
|
|
NotifyError::SanityCheck(error) => Some(error),
|
|
|
|
NotifyError::SendMsg(error) => Some(error),
|
|
|
|
NotifyError::PushAncillaryMessage | NotifyError::PartialSend => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-08 14:46:54 +01:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum SanityCheckError {
|
|
|
|
InvalidFdName(FdNameError),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for SanityCheckError {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match self {
|
|
|
|
SanityCheckError::InvalidFdName(error) => {
|
2023-12-08 16:21:00 +01:00
|
|
|
write!(f, "the value of FDNAME was invalid : {error}")
|
2023-12-08 14:46:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-08 16:21:00 +01:00
|
|
|
impl Error for SanityCheckError {
|
|
|
|
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
|
|
|
match self {
|
|
|
|
SanityCheckError::InvalidFdName(error) => Some(error),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-12-08 14:46:54 +01:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum FdNameError {
|
|
|
|
TooLong { length: usize, name: String },
|
|
|
|
NotAsciiNonControl { disallowed_char: char, name: String },
|
|
|
|
ContainColon(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for FdNameError {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match self {
|
2023-12-08 16:21:00 +01:00
|
|
|
FdNameError::TooLong { length, name } => write!(f, "the file descriptor name {name:?} is too long (is {length} characters and should be less than 255)"),
|
|
|
|
FdNameError::NotAsciiNonControl { disallowed_char, name } => write!(f, "the file descriptor name {name:?} contains invalid character '{disallowed_char}' (only ASCII allowed)"),
|
|
|
|
FdNameError::ContainColon(name) => write!(f, "the file descriptor name {name:?} contains a colon (':') which isn't allowed"),
|
2023-12-08 14:46:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-12-08 16:21:00 +01:00
|
|
|
|
|
|
|
impl Error for FdNameError {}
|