1use std::fmt;
7use std::io;
8
9#[non_exhaustive]
15#[derive(Debug)]
16pub enum HandoffError {
17 PeerMismatch,
19 Truncated,
21 CountMismatch,
23 BadMagic,
25 BadVersion,
27 BadChecksum,
29 TooMany {
31 max: u8,
33 },
34 VerifyFailed {
36 index: u8,
38 why: &'static str,
40 },
41 Timeout,
43 Os(io::Error),
45}
46
47impl fmt::Display for HandoffError {
48 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49 match self {
50 HandoffError::PeerMismatch => {
51 f.write_str("the hand-off sender is not the expected process or user")
52 }
53 HandoffError::Truncated => f.write_str("the hand-off message was truncated"),
54 HandoffError::CountMismatch => {
55 f.write_str("the descriptor count does not match the manifest")
56 }
57 HandoffError::BadMagic => f.write_str("not a hand-off manifest"),
58 HandoffError::BadVersion => f.write_str("unknown hand-off manifest version"),
59 HandoffError::BadChecksum => {
60 f.write_str("the hand-off manifest checksum does not match")
61 }
62 HandoffError::TooMany { max } => write!(f, "more than {max} listeners in one hand-off"),
63 HandoffError::VerifyFailed { index, why } => {
64 write!(f, "received listener {index} failed: {why}")
65 }
66 HandoffError::Timeout => f.write_str("the hand-off did not finish in time"),
67 HandoffError::Os(e) => write!(f, "{e}"),
68 }
69 }
70}
71
72impl std::error::Error for HandoffError {
73 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
74 match self {
75 HandoffError::Os(e) => Some(e),
76 _ => None,
77 }
78 }
79}