Files
aria2-rust-pro/crates/aria2-rust-pro-protocol/src/tracker/error.rs
T

45 lines
1.8 KiB
Rust

use super::{Display, Formatter};
/// Errors raised while parsing tracker announce, scrape, or UDP payloads.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum TrackerParseError {
/// The tracker bencode payload was malformed.
InvalidBencode(String),
/// A required field was missing from the payload.
MissingField(&'static str),
/// A hex-encoded value was malformed.
InvalidHex(String),
/// A peer entry was malformed.
InvalidPeer(String),
/// A UDP tracker packet was malformed.
InvalidUdpPacket(String),
/// A UDP tracker action code was unknown.
InvalidUdpAction(u32),
/// The response transaction identifier differed from the request identifier.
TransactionIdMismatch {
/// Transaction identifier the caller expected to receive.
expected: u32,
/// Transaction identifier that was actually received.
actual: u32,
},
}
impl Display for TrackerParseError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::InvalidBencode(reason) => write!(f, "invalid tracker bencode: {reason}"),
Self::MissingField(field) => write!(f, "missing tracker field: {field}"),
Self::InvalidHex(value) => write!(f, "invalid hex string: {value}"),
Self::InvalidPeer(reason) => write!(f, "invalid peer entry: {reason}"),
Self::InvalidUdpPacket(reason) => write!(f, "invalid udp tracker packet: {reason}"),
Self::InvalidUdpAction(action) => write!(f, "invalid udp tracker action id: {action}"),
Self::TransactionIdMismatch { expected, actual } => write!(
f,
"udp tracker transaction id mismatch: expected {expected}, got {actual}"
),
}
}
}
impl std::error::Error for TrackerParseError {}