Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error {
Show 19 variants Io { target: Option<SocketAddr>, source: Error, }, Timeout { target: Option<SocketAddr>, elapsed: Duration, request_id: i32, retries: u32, }, Snmp { target: Option<SocketAddr>, status: ErrorStatus, index: u32, oid: Option<Oid>, }, InvalidOid { kind: OidErrorKind, input: Option<Box<str>>, }, Decode { offset: usize, kind: DecodeErrorKind, }, Encode { kind: EncodeErrorKind, }, RequestIdMismatch { expected: i32, actual: i32, }, VersionMismatch { expected: Version, actual: Version, }, MessageTooLarge { size: usize, max: usize, }, UnknownEngineId { target: Option<SocketAddr>, }, NotInTimeWindow { target: Option<SocketAddr>, }, AuthenticationFailed { target: Option<SocketAddr>, kind: AuthErrorKind, }, DecryptionFailed { target: Option<SocketAddr>, kind: CryptoErrorKind, }, EncryptionFailed { target: Option<SocketAddr>, kind: CryptoErrorKind, }, InvalidCommunity { target: Option<SocketAddr>, }, NonIncreasingOid { previous: Oid, current: Oid, }, DuplicateOid { oid: Oid, }, GetBulkNotSupportedInV1, Config(String),
}
Expand description

The main error type for all async-snmp operations.

This enum covers all possible error conditions including network issues, protocol errors, encoding/decoding failures, and SNMPv3 security errors.

§Common Patterns

§Checking Error Type

Use pattern matching to handle specific error conditions:

use async_snmp::{Error, ErrorStatus};

fn is_retriable(error: &Error) -> bool {
    matches!(error,
        Error::Timeout { .. } |
        Error::Io { .. } |
        Error::NotInTimeWindow { .. }
    )
}

fn is_access_error(error: &Error) -> bool {
    matches!(error,
        Error::Snmp { status: ErrorStatus::NoAccess | ErrorStatus::AuthorizationError, .. } |
        Error::AuthenticationFailed { .. } |
        Error::InvalidCommunity { .. }
    )
}

§Extracting Target Address

Many errors include the target address for diagnostics:

use async_snmp::Error;

fn log_error(error: &Error) {
    if let Some(addr) = error.target() {
        println!("Error from {}: {}", addr, error);
    } else {
        println!("Error: {}", error);
    }
}

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.
§

Io

I/O error during network communication.

Fields

§source: Error
§

Timeout

Request timed out (after retries if configured).

Fields

§elapsed: Duration
§request_id: i32
§retries: u32
§

Snmp

SNMP protocol error returned by agent.

Fields

§index: u32
§

InvalidOid

Invalid OID format.

Fields

§input: Option<Box<str>>
§

Decode

BER decoding error.

Fields

§offset: usize
§

Encode

BER encoding error.

Fields

§

RequestIdMismatch

Response request ID doesn’t match.

Fields

§expected: i32
§actual: i32
§

VersionMismatch

Response version doesn’t match request.

Fields

§expected: Version
§actual: Version
§

MessageTooLarge

Message exceeds maximum size.

Fields

§size: usize
§max: usize
§

UnknownEngineId

Unknown engine ID (SNMPv3).

Fields

§

NotInTimeWindow

Message outside time window (SNMPv3).

Fields

§

AuthenticationFailed

Authentication failed (SNMPv3).

Fields

§

DecryptionFailed

Decryption failed (SNMPv3).

§

EncryptionFailed

Encryption failed (SNMPv3).

§

InvalidCommunity

Invalid community string.

Fields

§

NonIncreasingOid

Non-increasing OID detected during walk (agent misbehavior).

Returned when a walk operation receives an OID that is not lexicographically greater than the previous OID, which would cause an infinite loop. This indicates a non-conformant SNMP agent.

Only occurs with OidOrdering::Strict (the default).

Fields

§previous: Oid
§current: Oid
§

DuplicateOid

Walk detected a cycle (same OID returned twice).

Only occurs with OidOrdering::AllowNonIncreasing, which uses a HashSet to track all seen OIDs and detect cycles.

Fields

§oid: Oid
§

GetBulkNotSupportedInV1

GETBULK not supported in SNMPv1.

Returned when WalkMode::GetBulk is explicitly requested with an SNMPv1 client. GETBULK is only available in SNMPv2c and SNMPv3.

§

Config(String)

Configuration error.

Returned when client configuration is invalid (e.g., privacy without authentication, missing passwords).

Implementations§

Source§

impl Error

Source

pub fn decode(offset: usize, kind: DecodeErrorKind) -> Self

Create a decode error.

Source

pub fn encode(kind: EncodeErrorKind) -> Self

Create an encode error.

Source

pub fn auth(target: Option<SocketAddr>, kind: AuthErrorKind) -> Self

Create an authentication error.

Source

pub fn decrypt(target: Option<SocketAddr>, kind: CryptoErrorKind) -> Self

Create a decryption error.

Source

pub fn encrypt(target: Option<SocketAddr>, kind: CryptoErrorKind) -> Self

Create an encryption error.

Source

pub fn invalid_oid(kind: OidErrorKind) -> Self

Create an invalid OID error from a kind (no input string).

Source

pub fn invalid_oid_with_input( kind: OidErrorKind, input: impl Into<Box<str>>, ) -> Self

Create an invalid OID error with the input string that failed.

Source

pub fn target(&self) -> Option<SocketAddr>

Get the target address if this error has one.

Returns Some(addr) for network-related errors that have a known target, None for errors like OID parsing or encoding that aren’t target-specific.

§Example
use async_snmp::Error;
use std::time::Duration;

let error = Error::Timeout {
    target: Some("192.168.1.1:161".parse().unwrap()),
    elapsed: Duration::from_secs(5),
    request_id: 42,
    retries: 3,
};

assert_eq!(
    error.target().map(|a| a.to_string()),
    Some("192.168.1.1:161".to_string())
);

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

Auto Trait Implementations§

§

impl Freeze for Error

§

impl !RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more