Skip to main content

Error

Enum Error 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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: ErrorClass

Error class (Clause 18).

§code: ErrorCode

Error code (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.

Fields

§dnet: u16

Destination network rejected by the router.

§

RoutedPathCapacityExceeded

The client cannot safely allocate state for another routed path.

Fields

§capacity: usize

Maximum number of immediate-router/DNET path entries retained.

§

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

§required: DataLink

Data link the operation needs.

§actual: DataLink

Data link the endpoint’s transport carries.

§

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

§length: usize

Length of the NPDU or encoded link frame that was refused.

§limit: usize

The corresponding bound when this send was refused.

§

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.

Fields

§need: usize

Minimum bytes needed.

§have: usize

Bytes actually available.

§

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.

Fields

§requested: u64

The sequence number the read asked for.

§returned: Option<u64>

What the device numbered the first record it sent; None when it returned no records.

Implementations§

Source§

impl Error

Source

pub const fn protocol(class: ErrorClass, code: ErrorCode) -> Self

An Error PDU’s Error::Remote with its class and code.

Source

pub const fn reject(reason: RejectReason) -> Self

A Reject PDU’s Error::Remote with its reason.

Source

pub const fn abort(reason: AbortReason) -> Self

An Abort PDU’s Error::Remote with its reason.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn missing(offset: usize, label: &'static str) -> Self

Create a DecodingKind::Missing decoding error: a required member due at offset isn’t there.

Source

pub fn trailing(offset: usize, label: &'static str) -> Self

Create a DecodingKind::Trailing decoding error: octets from offset on that the value leaves unread.

Source

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.

Source

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.

Source

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.

Source

pub fn decode_fault(&self) -> Option<(usize, DecodingKind)>

The offset and kind of an Error::Decoding; None for any other error.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn buffer_too_short(need: usize, have: usize) -> Self

Create a buffer-too-short error.

Trait Implementations§

Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<DecodeError> for Error

Source§

fn from(error: DecodeError) -> Self

Converts to this type from the input type.
Source§

impl From<EncodeError> for Error

Source§

fn from(error: EncodeError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<RangeError> for Error

Source§

fn from(error: RangeError) -> Self

Converts to this type from the input type.
Source§

impl From<RemoteError> for Error

Source§

fn from(error: RemoteError) -> Self

Converts to this type from the input type.
Source§

impl From<SegmentationError> for Error

Source§

fn from(error: SegmentationError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Freeze for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.