1use thiserror::Error;
2
3#[derive(Debug, Eq, PartialEq, Error)]
5pub enum MarshalError {
6 #[error("Tried to marshal a message with the 'invalid' message type")]
8 InvalidMessageType,
9 #[error("Tried to marshal an empty UnixFd")]
11 EmptyUnixFd,
12 #[error("Error while trying to dup a UnixFd")]
14 DupUnixFd(nix::Error),
15 #[error("Errors occured while validating: {0}")]
17 Validation(crate::params::validation::Error),
18}
19
20impl From<crate::params::validation::Error> for MarshalError {
25 fn from(e: crate::params::validation::Error) -> Self {
26 MarshalError::Validation(e)
27 }
28}
29
30impl From<crate::signature::Error> for MarshalError {
31 fn from(e: crate::signature::Error) -> Self {
32 MarshalError::Validation(crate::params::validation::Error::InvalidSignature(e))
33 }
34}
35
36#[derive(Debug, PartialEq, Eq, Error)]
38pub enum UnmarshalError {
39 #[error("Found an empty struct while unmarshalling")]
41 EmptyStruct,
42 #[error("There were not enough bytes in the buffer to unmarshal the value")]
44 NotEnoughBytes,
45 #[error("There were not enough bytes in the buffer to unmarshal the collection")]
47 NotEnoughBytesForCollection,
48 #[error("Unmarshalling a message did not use all bytes in the body")]
50 NotAllBytesUsed,
51 #[error("A message indicated an invalid byteorder in the header")]
53 InvalidByteOrder,
54 #[error("A message indicated an invalid message type")]
56 InvalidMessageType,
57 #[error("There was a mismatch between expected an encountered signatures")]
60 WrongSignature,
61 #[error("Error encountered while validating input: {0}")]
63 Validation(crate::params::validation::Error),
64 #[error("A message contained an invalid header field")]
66 InvalidHeaderField,
67 #[error("A message contained an invalid header fields")]
69 InvalidHeaderFields,
70 #[error("A message contained unknown header fields")]
72 UnknownHeaderField,
73 #[error("Returned when data is encountered in padding between values. This is a sign of a corrupted message (or a bug in this library)")]
75 PaddingContainedData,
76 #[error("A boolean did contain something other than 0 or 1")]
78 InvalidBoolean,
79 #[error("No more values can be read from this message")]
81 EndOfMessage,
82 #[error("A message did not contain a signature for a header field")]
84 NoSignature,
85 #[error("A unix fd member had an index that is bigger than the size of the list of unix fds passed along with the message")]
87 BadFdIndex(usize),
88 #[error("When unmarshalling a Variant and there is not matching variant in the enum that had the unmarshal impl derived")]
90 NoMatchingVariantFound,
91}