use std::fmt;
use crate::Version;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
Cdr(rustorb_cdr::Error),
BadMagic([u8; 4]),
UnsupportedVersion(Version),
UnknownMessageType(u8),
InvalidFlags(u8),
Truncated {
expected: usize,
actual: usize,
},
TrailingBytes(usize),
MessageTooLarge(usize),
InvalidAddressingDisposition(i16),
TargetNotKey,
InvalidReplyStatus(u32),
InvalidLocateStatus(u32),
UnexpectedFragment,
FragmentInProgress,
FragmentMismatch,
FragmentTooLarge(usize),
FragmentNotSupported,
InvalidIorString(&'static str),
InvalidObjectUrl(&'static str),
UnexpectedProfileTag(u32),
UnsupportedIiopVersion(Version),
ComponentsInIiop1_0,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Cdr(e) => write!(f, "CDR error: {e}"),
Error::BadMagic(m) => write!(f, "bad GIOP magic {m:02x?}"),
Error::UnsupportedVersion(v) => write!(f, "unsupported GIOP version {v}"),
Error::UnknownMessageType(t) => write!(f, "unknown GIOP message type {t}"),
Error::InvalidFlags(b) => write!(f, "invalid GIOP 1.0 byte order {b:#04x}"),
Error::Truncated { expected, actual } => {
write!(
f,
"GIOP message truncated: need {expected} bytes, got {actual}"
)
}
Error::TrailingBytes(n) => write!(f, "{n} bytes after the GIOP message"),
Error::MessageTooLarge(n) => write!(f, "GIOP message of {n} bytes is too large"),
Error::InvalidAddressingDisposition(d) => {
write!(f, "invalid addressing disposition {d}")
}
Error::TargetNotKey => f.write_str("GIOP 1.0/1.1 requires an object key target"),
Error::InvalidReplyStatus(v) => write!(f, "invalid reply status {v}"),
Error::InvalidLocateStatus(v) => write!(f, "invalid locate status {v}"),
Error::UnexpectedFragment => f.write_str("fragment without a message to continue"),
Error::FragmentInProgress => f.write_str("a fragmented message is already in progress"),
Error::FragmentMismatch => {
f.write_str("fragment version or byte order differs from the first message")
}
Error::FragmentTooLarge(n) => {
write!(f, "reassembled message of {n} bytes exceeds the limit")
}
Error::FragmentNotSupported => f.write_str("GIOP 1.0 does not support fragments"),
Error::InvalidIorString(why) => write!(f, "invalid stringified IOR: {why}"),
Error::InvalidObjectUrl(why) => write!(f, "invalid object URL: {why}"),
Error::UnexpectedProfileTag(tag) => write!(f, "unexpected profile tag {tag}"),
Error::UnsupportedIiopVersion(v) => write!(f, "unsupported IIOP version {v}"),
Error::ComponentsInIiop1_0 => f.write_str("IIOP 1.0 profiles cannot have components"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Cdr(e) => Some(e),
_ => None,
}
}
}
impl From<rustorb_cdr::Error> for Error {
fn from(e: rustorb_cdr::Error) -> Error {
Error::Cdr(e)
}
}