Skip to main content

Error

Struct Error 

Source
pub struct Error(/* private fields */);
Expand description

The error of every function of the crate that can fail, and of the bindings that are built on it.

kind is what a caller matches on. Display says what is wrong, in the words of the specification where it has them, then why, and for octets that do not decode the field of the bindings where the decoding stopped:

use oxirush_aper::{ErrorKind, Reader};

// A number of the constraint (0..65535) is two octets, and one is there
let error = Reader::new(&[0x12]).unsigned(0, 65535).unwrap_err();
assert_eq!(error.kind(), ErrorKind::Decode);
assert_eq!(
    error.to_string(),
    "the octets do not decode: the octets end before the value does"
);

Two errors are equal when they have the same kind and the same message. An error is one pointer, so that a Result of a small value stays small.

Implementations§

Source§

impl Error

Source

pub fn new(kind: ErrorKind, what: impl Into<String>) -> Self

An error of a kind, which says what is wrong.

Source

pub fn kind(&self) -> ErrorKind

What went wrong, as a caller matches on it.

Source

pub fn because(self, why: impl Into<String>) -> Self

The same error, with the reason of what is wrong, which the message has after it.

Source

pub fn of(self, what: impl Into<String>) -> Self

The same error, told of what: what it said is wrong becomes the reason, where it gave none apart.

Source

pub fn with_kind(self, kind: ErrorKind) -> Self

The same error, of another kind.

Source

pub fn ie(&self) -> Option<ErrorIe>

The IE of a message that the error is about, when it is about one: an error of the kind MissingIe or UndecodableIe that the bindings of a protocol made.

use oxirush_aper::{Criticality, Error, ErrorIe};

// The IE 21 of an NG SETUP REQUEST, received with the criticality `ignore`
let ie = ErrorIe::new(21, Criticality::Ignore, Some(3));
let error = Error::undecodable("the DefaultPagingDRX does not decode").about_ie(ie);
assert_eq!(error.ie(), Some(ie));
assert_eq!(Error::argument("an MCC has three digits").ie(), None);
Source

pub fn about_ie(self, ie: ErrorIe) -> Self

The same error, about an IE of a message.

Source

pub fn reworded(self, reword: impl FnOnce(&str) -> String) -> Self

The same error, with the message that reword makes of the one that it has.

Source

pub fn reason(&self) -> String

The reason of what is wrong, where the message has one apart, and what is wrong otherwise, with the field of the bindings where a decoding stopped.

Source

pub fn fields(&self) -> impl Iterator<Item = &'static str> + '_

The fields of the bindings on the way to where a decoding stopped, the outermost first: none for an error that is no decoding error, or that stopped in no field.

Source

pub fn in_field(self, name: &'static str) -> Self

The same error, which was met in the field name of the bindings. A decoder of a SEQUENCE names the member that did not decode.

Source

pub fn decoding(self, name: &str) -> Self

Octets that are not a value of the type that ASN.1 names name: this error is why.

Source

pub fn encoding(self, name: &str) -> Self

A value of the type that ASN.1 names name that does not encode: this error is why.

Source§

impl Error

The errors that the bindings of an application protocol make of a PDU, of its message and of its IEs, in one wording for every protocol. A program that uses bindings matches on the kind of their errors, and makes none of these.

Source

pub fn wrong_message( expected: &str, held: Option<&str>, direction: &str, code: u8, ) -> Self

A PDU of another message than the one that ASN.1 names expected: held is the name of the message of its direction and of the procedure code, when the specification has one.

Source

pub fn no_protocol_ies(name: &str) -> Self

A PDU of the message that ASN.1 names name, which has no container of protocol IEs.

Source

pub fn no_message_of(direction: &str, code: u8) -> Self

A PDU whose direction and procedure code the specification has no message for, and so no object set.

Source

pub fn of_message(self, name: Option<&str>) -> Self

This error is why the message of a PDU does not decode as a container of protocol IEs: the message that ASN.1 names name, when the specification has one for the PDU.

Source

pub fn of_protocol_ies(self, count: usize) -> Self

This error is why count protocol IEs do not encode as a message.

Source

pub fn missing_ie(message: &str, ie: &str, field: &str) -> Self

The IE that a message names ie, which the field field requires, is not in a message of the type message.

use oxirush_aper::{Error, ErrorKind};

let error = Error::missing_ie("NGSetupRequest", "SupportedTAList", "areas");
assert_eq!(error.kind(), ErrorKind::MissingIe);
assert_eq!(
    error.to_string(),
    "this NGSetupRequest has no SupportedTAList, which the field `areas` requires"
);
Source

pub fn undecodable_ie(self, message: &str, ie: &str) -> Self

This error is why the IE that a message names ie does not decode, in a message of the type message.

use oxirush_aper::{ErrorKind, Reader};

// An ENUMERATED of four values and an extension marker, read from no octet
let codec = Reader::new(&[]).enumerated(4, 0, true).unwrap_err();
let error = codec.undecodable_ie("NGSetupRequest", "DefaultPagingDRX");
assert_eq!(error.kind(), ErrorKind::UndecodableIe);
assert_eq!(
    error.to_string(),
    "the DefaultPagingDRX of this NGSetupRequest does not decode: the octets end before \
     the value does"
);
Source

pub fn outside_its_type(self, name: &str) -> Self

A value of the type that ASN.1 names name that is written in JSON and does not encode: it is outside a constraint of its type, and so no value of that type. This error is what the codec said of it.

Source§

impl Error

Source

pub fn argument(what: impl Into<String>) -> Self

An argument that a function does not take, and what it takes.

Source

pub fn unknown_message(what: impl Into<String>) -> Self

A name of a message, or a direction and a procedure code, that the protocol does not have.

Source

pub fn unknown_ie(what: impl Into<String>) -> Self

A name or an identifier of an IE that the protocol does not have, or has no type for where it is.

Source

pub fn path(what: impl Into<String>) -> Self

A path that is not well formed.

Source

pub fn no_such_member(what: impl Into<String>) -> Self

A name that the type at that place cannot have.

Source

pub fn nothing_selected(what: impl Into<String>) -> Self

An edit whose path selects nothing.

Source

pub fn not_opened(what: impl Into<String>) -> Self

A path through the type that octets carry, before they are opened.

Source

pub fn undecodable(what: impl Into<String>) -> Self

A path into an IE or a transfer that is there and did not decode.

Source

pub fn value(what: impl Into<String>) -> Self

A JSON value that is not a value of its ASN.1 type.

Source

pub fn form(what: impl Into<String>) -> Self

JSON that is not written as a tree or as a view.

Source

pub fn edit(what: impl Into<String>) -> Self

An edit that is refused.

Source

pub fn limit(what: impl Into<String>) -> Self

Nesting or a number of occurrences over the limits of the inspection.

Trait Implementations§

Source§

impl Clone for Error

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Error

Source§

fn fmt(&self, formatter: &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 Eq for Error

Source§

impl Error for Error

1.30.0 · 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 PartialEq for Error

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

§

impl UnwindSafe 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.