1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
use std::error::Error; use std::fmt; use std::io; use std::result; pub type Result<T> = result::Result<T, StreamDelimitError>; #[derive(Debug)] pub enum StreamDelimitError { #[cfg(feature = "with_kafka")] KafkaInitializeError(::kafka::error::Error), VarintDecodeError(io::Error), InvalidStreamTypeError(String), VarintDecodeMaxBytesError, } impl fmt::Display for StreamDelimitError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { #[cfg(feature = "with_kafka")] StreamDelimitError::KafkaInitializeError(ref e) => { write!(f, "Couldn't initialize kafka consumer: {}", e) } StreamDelimitError::VarintDecodeError(ref e) => { write!(f, "Couldn't decode leading varint: {}", e) } StreamDelimitError::InvalidStreamTypeError(ref t) => write!( f, "Invalid stream type: {} (only support single,leb128,varint)", t ), StreamDelimitError::VarintDecodeMaxBytesError => { write!(f, "Exceeded max attempts to decode leading varint") } } } } impl Error for StreamDelimitError { fn description(&self) -> &str { match *self { #[cfg(feature = "with_kafka")] StreamDelimitError::KafkaInitializeError(_) => "couldn't initialize kafka consumer", StreamDelimitError::VarintDecodeError(_) | StreamDelimitError::VarintDecodeMaxBytesError => "couldn't decode leading varint", StreamDelimitError::InvalidStreamTypeError(_) => "invalid stream type", } } fn cause(&self) -> Option<&dyn Error> { match *self { #[cfg(feature = "with_kafka")] StreamDelimitError::KafkaInitializeError(ref e) => Some(e), StreamDelimitError::VarintDecodeError(ref e) => Some(e), StreamDelimitError::InvalidStreamTypeError(_) | StreamDelimitError::VarintDecodeMaxBytesError => None, } } }