rustbus/wire/
errors.rs

1use thiserror::Error;
2
3/// Errors that can occur while marshalling a value into a dbus message
4#[derive(Debug, Eq, PartialEq, Error)]
5pub enum MarshalError {
6    /// Tried to marshal a message with the "invalid" message type
7    #[error("Tried to marshal a message with the 'invalid' message type")]
8    InvalidMessageType,
9    /// Tried to marshal an empty UnixFd
10    #[error("Tried to marshal an empty UnixFd")]
11    EmptyUnixFd,
12    /// Error while trying to dup a UnixFd
13    #[error("Error while trying to dup a UnixFd")]
14    DupUnixFd(nix::Error),
15    /// Errors occuring while validating the input
16    #[error("Errors occured while validating: {0}")]
17    Validation(crate::params::validation::Error),
18}
19
20//--------
21// Conversion to MarshalError
22//--------
23
24impl 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/// Errors that can  occur while unmarshaling a value from a dbus message
37#[derive(Debug, PartialEq, Eq, Error)]
38pub enum UnmarshalError {
39    /// Found an empty struct while unmarshalling
40    #[error("Found an empty struct while unmarshalling")]
41    EmptyStruct,
42    /// There were not enough bytes in the buffer to unmarshal the value
43    #[error("There were not enough bytes in the buffer to unmarshal the value")]
44    NotEnoughBytes,
45    /// There were not enough bytes in the buffer to unmarshal the collection
46    #[error("There were not enough bytes in the buffer to unmarshal the collection")]
47    NotEnoughBytesForCollection,
48    /// Unmarshalling a message did not use all bytes in the body
49    #[error("Unmarshalling a message did not use all bytes in the body")]
50    NotAllBytesUsed,
51    /// A message indicated an invalid byteorder in the header
52    #[error("A message indicated an invalid byteorder in the header")]
53    InvalidByteOrder,
54    /// A message indicated an invalid message type
55    #[error("A message indicated an invalid message type")]
56    InvalidMessageType,
57    /// There was a mismatch between expected an encountered signatures
58    /// (e.g. trying to unmarshal a string when there is a u64 in the message)
59    #[error("There was a mismatch between expected an encountered signatures")]
60    WrongSignature,
61    /// Any error encountered while validating input
62    #[error("Error encountered while validating input: {0}")]
63    Validation(crate::params::validation::Error),
64    /// A message contained an invalid header field
65    #[error("A message contained an invalid header field")]
66    InvalidHeaderField,
67    /// A message contained an invalid header fields
68    #[error("A message contained an invalid header fields")]
69    InvalidHeaderFields,
70    /// A message contained unknown header fields
71    #[error("A message contained unknown header fields")]
72    UnknownHeaderField,
73    /// Returned when data is encountered in padding between values. This is a sign of a corrupted message (or a bug in this library)
74    #[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    /// A boolean did contain something other than 0 or 1
77    #[error("A boolean did contain something other than 0 or 1")]
78    InvalidBoolean,
79    /// No more values can be read from this message
80    #[error("No more values can be read from this message")]
81    EndOfMessage,
82    /// A message did not contain a signature for a header field
83    #[error("A message did not contain a signature for a header field")]
84    NoSignature,
85    /// A unix fd member had an index that is bigger than the size of the list of unix fds passed along with the message
86    #[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    /// When unmarshalling a Variant and there is not matching variant in the enum that had the unmarshal impl derived
89    #[error("When unmarshalling a Variant and there is not matching variant in the enum that had the unmarshal impl derived")]
90    NoMatchingVariantFound,
91}