CniError

Enum CniError 

Source
pub enum CniError {
Show 14 variants Io(Error), Json(Error), Incompatible(Version), MissingInput, MissingOutput, MissingEnv { var: &'static str, err: VarError, }, InvalidEnv { var: &'static str, err: Box<dyn Error>, }, NoCwd, MissingPlugin { name: String, err: Error, }, Delegated { plugin: String, err: Box<Self>, }, Generic(String), Debug(Box<dyn Debug>), MissingField(&'static str), InvalidField { field: &'static str, expected: &'static str, value: Value, },
}
Expand description

All errors emitted by this library, plus a few others.

Variants§

§

Io(Error)

Catch-all wrapper for I/O errors.

§

Json(Error)

Catch-all wrapper for JSON serialization and deserialization.

§

Incompatible(Version)

When the CNI version requested by the runtime is not supported.

The Version in the error is the CNI version provided, not ours.

Also see VersionReply.

§

MissingInput

When nothing is provided on STDIN.

§

MissingOutput

When a delegated plugin doesn’t output anything on STDOUT.

§

MissingEnv

When a required environment variable is missing.

Fields

§var: &'static str

the variable name

§err: VarError

the underlying error

§

InvalidEnv

When an environment variable couldn’t be parsed or is invalid.

Fields

§var: &'static str

the variable name

§err: Box<dyn Error>

the underlying error

§

NoCwd

When the current working directory cannot be obtained (for delegation).

§

MissingPlugin

When a delegated plugin cannot be found on CNI_PATH.

Fields

§name: String

the name of the plugin binary

§err: Error

the underlying error

§

Delegated

Wrapper for errors in relation to a delegated plugin.

Fields

§plugin: String

the name of the plugin binary

§err: Box<Self>

the underlying error

§

Generic(String)

A generic error as a string.

This error variant is not used in the library, but is provided for plugin implementations to make use of without needing to make their own error type.

§Example

CniError::Generic("a total catastrophe".into());
§

Debug(Box<dyn Debug>)

A debug error as anything that implements Debug.

This error variant is not used in the library, but is provided for plugin implementations to make use of without needing to make their own error type.

§Example

CniError::Debug(Box::new(("hello", "world", vec![1, 2, 3])));
§

MissingField(&'static str)

When a field in configuration is missing.

This error variant is not used in the library, but is provided for plugin implementations to make use of without needing to make their own error type.

§Example

CniError::MissingField("ipam.type");
§

InvalidField

When a field in configuration is invalid.

This error variant is not used in the library, but is provided for plugin implementations to make use of without needing to make their own error type.

§Example

CniError::InvalidField {
    field: "ipam.pool",
    expected: "string",
    value: Value::Null,
};

Fields

§field: &'static str

the name or path of the invalid field

§expected: &'static str

the value or type the field was expected to be

§value: Value

the actual value or a facsimile thereof

Implementations§

Source§

impl CniError

Source

pub fn into_reply(self, cni_version: Version) -> ErrorReply<'static>

Convert a CniError into an ErrorReply.

ErrorReplys can be used with reply, but require cni_version to be set to the input configuration’s. This method makes it easier to create errors (including with the ? operator, from foreign error types) and only populate the version field when ready to send the reply.

It’s recommended to add an implementation of this if you make your own error type.

Trait Implementations§

Source§

impl Debug for CniError

Source§

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

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

impl Display for CniError

Source§

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

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

impl Error for CniError

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<Error> for CniError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for CniError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.