//! Crate-level RPC error type. //! //! Hoisted from per-module enums in M2 wave 2 — see `design/followups.md` F8. //! Every parser/encoder in `mxaccess-rpc` returns this single shared //! [`RpcError`] so consumers can match on one error surface across PDU //! decode, OBJREF parse, ORPC `ResolveOxid` body decode, and //! `IRemUnknown::RemQueryInterface` response decode. //! //! Variants here are the union of what M1 wave 1 defined locally in //! `pdu.rs` and `objref.rs` (`design/followups.md` F8 source list), //! plus a generic [`RpcError::Decode`] for one-off conditions wave 2's //! ORPC parsers need (referent-id mismatches, conformant-array max-count //! underflow, NDR alignment overrun) without growing the enum further. use thiserror::Error; /// Errors raised by any codec under `mxaccess-rpc`. #[derive(Debug, Error, PartialEq, Eq)] #[non_exhaustive] pub enum RpcError { /// Buffer was shorter than required to decode the type. #[error("short read: expected {expected} bytes, got {actual}")] ShortRead { expected: usize, actual: usize }, /// Packet type byte at offset 2 (`DceRpcPdu.cs:52`) did not match the /// expected `DceRpcPacketType` for the parser invoked. #[error("unexpected packet type {actual}, expected {expected}")] UnexpectedPacketType { expected: u8, actual: u8 }, /// Packet type byte was not a known [`crate::pdu::PacketType`] value. #[error("unknown packet type byte {0}")] UnknownPacketType(u8), /// `header.frag_length` is inconsistent with the supplied buffer or /// `auth_length` (`DceRpcPdu.cs:94,150,188,226,101-104,156-159,195-198`). #[error( "fragment length {frag_length} inconsistent with buffer length {buffer_len} \ (auth_length={auth_length})" )] InvalidFragmentLength { frag_length: usize, buffer_len: usize, auth_length: usize, }, /// A bind PDU's per-context list ran past `frag_length` /// (`DceRpcPdu.cs:237`) or a syntax identifier was truncated /// (`DceRpcPdu.cs:354`). #[error("truncated bind body at offset {offset}; need {need} bytes, frag_length={frag_length}")] TruncatedBindBody { offset: usize, need: usize, frag_length: usize, }, /// Auth-trailer offset is below the 16-byte header /// (`DceRpcPdu.cs:341-345`). #[error("invalid auth trailer offset {offset}")] InvalidAuthTrailer { offset: usize }, /// Tried to extract an auth value from a PDU whose `auth_length` is 0 /// (`DceRpcPdu.cs:336-339`). #[error("PDU has no auth value")] MissingAuthValue, /// Generic decode failure with a position and reason. Used by ORPC /// body decoders for one-off conditions that don't justify a typed /// variant (e.g. NDR conformant-array max-count underflow per /// `ObjectExporterMessages.cs:66-69`, referent-id of zero with no /// trailing status per `:57-61`, NDR alignment overrun, etc.). #[error("decode at offset {offset} ({reason}); buffer len {buffer_len}")] Decode { offset: usize, reason: &'static str, buffer_len: usize, }, }