1use std::fmt;
6use std::io;
7
8#[non_exhaustive]
14#[derive(Debug)]
15pub enum InheritError {
16 BadCount,
18 TooMany {
20 max: u32,
22 },
23 NotASocket {
25 fd: i32,
27 },
28 NotListening {
30 fd: i32,
32 },
33 WrongKind {
35 fd: i32,
37 },
38 NamesMismatch,
40 PidFdMismatch,
42 Os(io::Error),
44}
45
46impl fmt::Display for InheritError {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 match self {
49 InheritError::BadCount => f.write_str("LISTEN_FDS is not a valid count"),
50 InheritError::TooMany { max } => write!(f, "more than {max} inherited descriptors"),
51 InheritError::NotASocket { fd } => write!(f, "descriptor {fd} is not a socket"),
52 InheritError::NotListening { fd } => {
53 write!(f, "descriptor {fd} is not a listening socket")
54 }
55 InheritError::WrongKind { fd } => {
56 write!(f, "descriptor {fd} is not a TCP or Unix stream socket")
57 }
58 InheritError::NamesMismatch => f.write_str("LISTEN_FDNAMES does not match LISTEN_FDS"),
59 InheritError::PidFdMismatch => {
60 f.write_str("LISTEN_PIDFDID does not match this process")
61 }
62 InheritError::Os(e) => write!(f, "{e}"),
63 }
64 }
65}
66
67impl std::error::Error for InheritError {
68 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
69 match self {
70 InheritError::Os(e) => Some(e),
71 _ => None,
72 }
73 }
74}