#[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
Io
I/O error during network communication.
Timeout
Request timed out (after retries if configured).
Snmp
SNMP protocol error returned by agent.
InvalidOid
Invalid OID format.
Decode
BER decoding error.
Encode
BER encoding error.
Fields
kind: EncodeErrorKindRequestIdMismatch
Response request ID doesn’t match.
VersionMismatch
Response version doesn’t match request.
MessageTooLarge
Message exceeds maximum size.
UnknownEngineId
Unknown engine ID (SNMPv3).
Fields
target: Option<SocketAddr>NotInTimeWindow
Message outside time window (SNMPv3).
Fields
target: Option<SocketAddr>AuthenticationFailed
Authentication failed (SNMPv3).
DecryptionFailed
Decryption failed (SNMPv3).
EncryptionFailed
Encryption failed (SNMPv3).
InvalidCommunity
Invalid community string.
Fields
target: Option<SocketAddr>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).
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.
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
impl Error
Sourcepub fn decode(offset: usize, kind: DecodeErrorKind) -> Self
pub fn decode(offset: usize, kind: DecodeErrorKind) -> Self
Create a decode error.
Sourcepub fn encode(kind: EncodeErrorKind) -> Self
pub fn encode(kind: EncodeErrorKind) -> Self
Create an encode error.
Sourcepub fn auth(target: Option<SocketAddr>, kind: AuthErrorKind) -> Self
pub fn auth(target: Option<SocketAddr>, kind: AuthErrorKind) -> Self
Create an authentication error.
Sourcepub fn decrypt(target: Option<SocketAddr>, kind: CryptoErrorKind) -> Self
pub fn decrypt(target: Option<SocketAddr>, kind: CryptoErrorKind) -> Self
Create a decryption error.
Sourcepub fn encrypt(target: Option<SocketAddr>, kind: CryptoErrorKind) -> Self
pub fn encrypt(target: Option<SocketAddr>, kind: CryptoErrorKind) -> Self
Create an encryption error.
Sourcepub fn invalid_oid(kind: OidErrorKind) -> Self
pub fn invalid_oid(kind: OidErrorKind) -> Self
Create an invalid OID error from a kind (no input string).
Sourcepub fn invalid_oid_with_input(
kind: OidErrorKind,
input: impl Into<Box<str>>,
) -> Self
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.
Sourcepub fn target(&self) -> Option<SocketAddr>
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())
);