use thiserror::Error;
#[derive(Debug, Eq, PartialEq, Error)]
pub enum MarshalError {
#[error("Tried to marshal a message with the 'invalid' message type")]
InvalidMessageType,
#[error("Tried to marshal an empty UnixFd")]
EmptyUnixFd,
#[error("Error while trying to dup a UnixFd")]
DupUnixFd(nix::Error),
#[error("Errors occured while validating: {0}")]
Validation(crate::params::validation::Error),
}
impl From<crate::params::validation::Error> for MarshalError {
fn from(e: crate::params::validation::Error) -> Self {
MarshalError::Validation(e)
}
}
impl From<crate::signature::Error> for MarshalError {
fn from(e: crate::signature::Error) -> Self {
MarshalError::Validation(crate::params::validation::Error::InvalidSignature(e))
}
}
#[derive(Debug, PartialEq, Eq, Error)]
pub enum UnmarshalError {
#[error("Found an empty struct while unmarshalling")]
EmptyStruct,
#[error("There were not enough bytes in the buffer to unmarshal the value")]
NotEnoughBytes,
#[error("There were not enough bytes in the buffer to unmarshal the collection")]
NotEnoughBytesForCollection,
#[error("Unmarshalling a message did not use all bytes in the body")]
NotAllBytesUsed,
#[error("A message indicated an invalid byteorder in the header")]
InvalidByteOrder,
#[error("A message indicated an invalid message type")]
InvalidMessageType,
#[error("There was a mismatch between expected an encountered signatures")]
WrongSignature,
#[error("Error encountered while validating input: {0}")]
Validation(crate::params::validation::Error),
#[error("A message contained an invalid header field")]
InvalidHeaderField,
#[error("A message contained an invalid header fields")]
InvalidHeaderFields,
#[error("A message contained unknown header fields")]
UnknownHeaderField,
#[error("Returned when data is encountered in padding between values. This is a sign of a corrupted message (or a bug in this library)")]
PaddingContainedData,
#[error("A boolean did contain something other than 0 or 1")]
InvalidBoolean,
#[error("No more values can be read from this message")]
EndOfMessage,
#[error("A message did not contain a signature for a header field")]
NoSignature,
#[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")]
BadFdIndex(usize),
#[error("When unmarshalling a Variant and there is not matching variant in the enum that had the unmarshal impl derived")]
NoMatchingVariantFound,
}