#[non_exhaustive]pub enum Error {
Show 17 variants
Remote(RemoteError),
Structured {
class: ErrorClass,
code: ErrorCode,
detail: Box<ErrorDetail>,
},
RoutedPathTooLong {
dnet: u16,
},
RoutedPathCapacityExceeded {
capacity: usize,
},
UnsupportedTransport {
required: DataLink,
actual: DataLink,
},
SendTooLong {
length: usize,
limit: usize,
},
Encoding(String),
Encode(EncodeError),
Decoding(DecodeError),
Transport(Error),
Timeout(Duration),
Segmentation(SegmentationError),
BufferTooShort {
need: usize,
have: usize,
},
OutOfRange(String),
Range(RangeError),
ReadRangeViolation(ReadRangeViolation),
LogNotAdvancing {
requested: u64,
returned: Option<u64>,
},
}Expand description
Top-level error type for the BACnet library.
It is #[non_exhaustive], so a match on it outside this crate needs a
wildcard arm. Some variants exist only with a feature, and any crate in a
build can turn that on: Error::Transport needs std, and the variants
that hold a String or a Box need alloc. Without the attribute a
match written against a smaller build would stop compiling (#1604).
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Remote(RemoteError)
A peer’s Error, Reject or Abort PDU that turned a confirmed request
down (Clauses 20.1.5 to 20.1.7). An Error PDU whose Clause 21
production carries more than the class and code is
Error::Structured (with alloc) instead.
Structured
BACnet error response whose Clause 21 production carries more than the
class and code: ChangeList-Error, CreateObject-Error,
WritePropertyMultiple-Error, SubscribeCOVPropertyMultiple-Error,
ConfirmedPrivateTransfer-Error or VTClose-Error. detail holds the
extra fields; a body whose optional fields are all absent is reported
as Error::Remote. Only with alloc.
Fields
class: ErrorClassError class (Clause 18).
detail: Box<ErrorDetail>The production’s fields after the class and code. Boxed so the
rare structured error does not widen every Result<_, Error>.
RoutedPathTooLong
A router reported that the active message was too long for a routed path.
RoutedPathCapacityExceeded
The client cannot safely allocate state for another routed path.
UnsupportedTransport
The endpoint’s transport cannot carry the requested operation, such as a BBMD management request through a data link other than BACnet/IP. Nothing was sent.
Fields
SendTooLong
A definite length refusal before any bytes of this send were written or admitted to a transport’s write queue. The limit may apply to the NPDU or its full link envelope, including data attributes. An I/O failure, including an uncertain partial write, must not use this.
Fields
Encoding(String)
Error encoding a PDU, with a formatted message. Only with alloc;
Error::Encode is the static form, which the codec crates return.
Encode(EncodeError)
A value an encoder or validator refused, with a static label
(#1802). The encoders and validators of bacnet-encoding and
bacnet-services report this form.
Decoding(DecodeError)
Error decoding received data, with a static label and its numbers (#1646, #1776). Every decoder reports this form.
Transport(Error)
Transport-level I/O error. Only with the std feature, which has
std::io.
Timeout(Duration)
Request timed out.
Segmentation(SegmentationError)
A payload that can’t be segmented, segments that can’t be reassembled, or a segmented request a peer can’t take (#1802).
BufferTooShort
Buffer too short for the expected data.
OutOfRange(String)
Value out of valid range, with a formatted message. Only with
alloc; Error::Range is the static form.
Range(RangeError)
A value a checked constructor refused, with a static label (#1646),
such as an object type or instance
ObjectIdentifier::new
can’t encode.
ReadRangeViolation(ReadRangeViolation)
A well-formed ReadRange acknowledgement that breaks a rule the client
checks against the request it answers, so the client refused it. The
acknowledgement decoded; a malformed one is Error::Decoding
instead. Read again leniently to keep its items.
LogNotAdvancing
A paged log read asked for the records from one sequence number and the device answered with a page starting before it, so reading on would repeat records instead of advancing; or answered with none although its record counts say it holds that record. Some devices clamp a reference past their sequence wrap back to the oldest record, or number the record after the wrap 0; read such a log by position instead.
Implementations§
Source§impl Error
impl Error
Sourcepub const fn protocol(class: ErrorClass, code: ErrorCode) -> Self
pub const fn protocol(class: ErrorClass, code: ErrorCode) -> Self
An Error PDU’s Error::Remote with its class and code.
Sourcepub const fn reject(reason: RejectReason) -> Self
pub const fn reject(reason: RejectReason) -> Self
A Reject PDU’s Error::Remote with its reason.
Sourcepub const fn abort(reason: AbortReason) -> Self
pub const fn abort(reason: AbortReason) -> Self
An Abort PDU’s Error::Remote with its reason.
Sourcepub fn with_detail(
class: ErrorClass,
code: ErrorCode,
detail: Option<ErrorDetail>,
) -> Self
pub fn with_detail( class: ErrorClass, code: ErrorCode, detail: Option<ErrorDetail>, ) -> Self
The error an Error PDU reports: Error::Structured when its body
carried a detail, Error::Remote otherwise. Only with alloc.
Sourcepub fn remote(&self) -> Option<RemoteError>
pub fn remote(&self) -> Option<RemoteError>
The peer’s answer this error reports, without a structured error’s
detail: the RemoteError of Error::Remote, and an Error with
the class and code of Error::Structured. None for any other
error, which no peer sent.
Sourcepub fn decoding(offset: usize, label: &'static str) -> Self
pub fn decoding(offset: usize, label: &'static str) -> Self
Create a DecodingKind::InvalidEncoding decoding error at the given
byte offset: contents whose encoding isn’t valid for their datatype.
Build a DecodeError directly for a label that names a context or
a number.
Sourcepub fn decoding_kind(
kind: DecodingKind,
offset: usize,
label: &'static str,
) -> Self
pub fn decoding_kind( kind: DecodingKind, offset: usize, label: &'static str, ) -> Self
Create an Error::Decoding of kind at the given byte offset,
described by a static label.
Sourcepub fn invalid_tag(offset: usize, label: &'static str) -> Self
pub fn invalid_tag(offset: usize, label: &'static str) -> Self
Create a DecodingKind::InvalidTag decoding error: a tag at
offset that doesn’t fit there.
Sourcepub fn missing(offset: usize, label: &'static str) -> Self
pub fn missing(offset: usize, label: &'static str) -> Self
Create a DecodingKind::Missing decoding error: a required member
due at offset isn’t there.
Sourcepub fn trailing(offset: usize, label: &'static str) -> Self
pub fn trailing(offset: usize, label: &'static str) -> Self
Create a DecodingKind::Trailing decoding error: octets from
offset on that the value leaves unread.
Sourcepub fn out_of_range(offset: usize, label: &'static str) -> Self
pub fn out_of_range(offset: usize, label: &'static str) -> Self
Create a DecodingKind::OutOfRange decoding error: a value at
offset too large for its field, or outside its range.
Sourcepub fn overflow(offset: usize, label: &'static str) -> Self
pub fn overflow(offset: usize, label: &'static str) -> Self
Create a DecodingKind::Overflow decoding error: more items, or a
longer tag, than the decoder takes.
Sourcepub fn to_decode_error(&self, offset: usize) -> DecodeError
pub fn to_decode_error(&self, offset: usize) -> DecodeError
This error, an inner reader’s refusal, as a static DecodeError at
offset, for a decoder that reports it as its own fault there and
names its own context or item (#1776). A decoding error keeps its
kind, context, label, values and index; a range error is
DecodingKind::OutOfRange with its label and values; a short buffer
is DecodingKind::Missing with its sizes. Any other error, which a
decoder doesn’t return, is an DecodingKind::InvalidEncoding
labelled malformed.
Sourcepub fn decode_fault(&self) -> Option<(usize, DecodingKind)>
pub fn decode_fault(&self) -> Option<(usize, DecodingKind)>
The offset and kind of an Error::Decoding; None for any other
error.
Sourcepub fn reject_reason(&self) -> Option<RejectReason>
pub fn reject_reason(&self) -> Option<RejectReason>
The Reject reason a responder answers a confirmed request with when
this error refused it while decoding its parameters (Clauses 18.9 and
20.1.8): the reason itself for a Reject’s Error::Remote, the kind’s reason
for a decoding error (the table on
DecodingKind::reject_reason), and MISSING_REQUIRED_PARAMETER for
Error::BufferTooShort, a member cut short because the data ran out
before it was complete. None for any other error, which no decoder
of the request’s parameters reports.
Sourcepub fn into_request_reject(self) -> Self
pub fn into_request_reject(self) -> Self
This error, met decoding a confirmed request’s own parameters, as the
Reject’s Error::Remote a responder answers with: the
reject_reason when it is a syntax fault, the
error unchanged otherwise.
A responder converts only the request’s decode with this. A decoding error met later, once the service has started to run, is no reason to reject the request (Clause 20.1.8), so it stays as it is.
Sourcepub fn encode(label: &'static str) -> Self
pub fn encode(label: &'static str) -> Self
Create an Error::Encode described by a static label. Build an
EncodeError directly for a label that names a context or a
number.
Sourcepub fn range(label: &'static str) -> Self
pub fn range(label: &'static str) -> Self
Create an Error::Range described by a static label. Build a
RangeError directly for a label with numbers.
Sourcepub fn into_encode_refusal(self) -> Self
pub fn into_encode_refusal(self) -> Self
This error, met checking octets an encoder was handed to copy onto
the wire, such as a captured raw value, as the encoder’s own
Error::Encode (#1802). A decoder’s refusal keeps its offset (see
EncodeError::from_decode); a short buffer or another refusal keeps
the label and numbers to_decode_error gives
it, without an offset; an Error::Encode stays as it is.
Sourcepub fn buffer_too_short(need: usize, have: usize) -> Self
pub fn buffer_too_short(need: usize, have: usize) -> Self
Create a buffer-too-short error.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()