Skip to main content

Error

Struct Error 

Source
pub struct Error { /* private fields */ }
Expand description

Any error raised by the client, and the command it belongs to.

Match on kind to tell errors apart, and read command to know which command produced it:

if let Err(e) = result {
    if matches!(e.kind(), ErrorKind::Timeout(_)) {
        eprintln!("{:?} timed out", e.command());
    }
}

Implementations§

Source§

impl Error

Source

pub fn kind(&self) -> &ErrorKind

What the error is.

Source

pub fn into_kind(self) -> ErrorKind

Consumes the error and yields its kind, for matching by value.

Source

pub fn context(&self) -> Option<&ErrorContext>

The command the error belongs to, when the client knows it.

None for an error raised outside any command, such as a connection timeout.

Source

pub fn command(&self) -> Option<&str>

The name of the command the error belongs to — shorthand for context().map(ErrorContext::command).

Source

pub fn is_connection_error(&self) -> bool

Whether the connection to the server is what failed: the transport broke, the peer went away, or a reply could not be framed.

True for a transport or TLS failure, an end of stream, a disconnection, the loss of the network task, and a RESP framing failure — the last one because a stream the parser lost track of cannot carry another command, so the client drops the connection and reconnects. False for anything the server answered (is_server_error), for a timeout (is_timeout), and for a decode failure on a well-framed reply, which fails one command only.

The command may or may not have run: the answer, if any, was lost with the connection.

Source

pub fn is_timeout(&self) -> bool

Whether a deadline expired before the operation completed.

Covers both Config::connect_timeout and Config::command_timeout; command tells them apart, being None for a connection that never got to send anything. A blocking command reaching its own server-side timeout is not an error at all — it replies nil, so it arrives as None.

Source

pub fn is_server_error(&self) -> bool

Whether the server answered, and answered an error.

The connection is healthy and the command reached the server: what failed is the command itself — a wrong type, a missing script, a refused authentication. Match on RedisError::kind for the exact code.

Source

pub fn is_retryable(&self) -> bool

Whether the failure is transient, so that sending the command again may succeed.

True for every connection error, for a timeout, and for the server codes that ask for a replay: TRYAGAIN, CLUSTERDOWN, MASTERDOWN and NOMASTERLINK.

§Warning

Transient does not mean the command did not run. A connection that dies or a deadline that expires after the server applied the write leaves no way to tell it apart from one that died before. Replay only commands that are safe to apply twice, or make them idempotent first — INCR replayed on a lost reply counts twice.

Trait Implementations§

Source§

impl Clone for Error

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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, f: &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
Source§

impl Error for Error

Source§

fn custom<T>(msg: T) -> Self
where T: Display,

Raised when there is general error when deserializing a type. Read more
Source§

fn invalid_type(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self

Raised when a Deserialize receives a type different from what it was expecting. Read more
Source§

fn invalid_value(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self

Raised when a Deserialize receives a value of the right type but that is wrong for some other reason. Read more
Source§

fn invalid_length(len: usize, exp: &dyn Expected) -> Self

Raised when deserializing a sequence or map and the input data contains too many or too few elements. Read more
Source§

fn unknown_variant(variant: &str, expected: &'static [&'static str]) -> Self

Raised when a Deserialize enum type received a variant with an unrecognized name.
Source§

fn unknown_field(field: &str, expected: &'static [&'static str]) -> Self

Raised when a Deserialize struct type received a field with an unrecognized name.
Source§

fn missing_field(field: &'static str) -> Self

Raised when a Deserialize struct type expected to receive a required field with a particular name but that field was not present in the input.
Source§

fn duplicate_field(field: &'static str) -> Self

Raised when a Deserialize struct type received more than one of the same field.
Source§

impl Error for Error

Source§

fn custom<T>(msg: T) -> Self
where T: Display,

Used when a Serialize implementation encounters any error while serializing a type. Read more
Source§

impl From<ClientError> for Error

Source§

fn from(value: ClientError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(value: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Available on crate feature rustls only.
Source§

fn from(value: Error) -> Self

Converts to this type from the input type.
Source§

impl From<ErrorKind> for Error

Source§

fn from(kind: ErrorKind) -> Self

Converts to this type from the input type.
Source§

impl From<FromUtf8Error> for Error

Source§

fn from(value: FromUtf8Error) -> Self

Converts to this type from the input type.
Source§

impl From<InvalidDnsNameError> for Error

Available on crate feature rustls only.
Source§

fn from(value: InvalidDnsNameError) -> Self

Converts to this type from the input type.
Source§

impl From<JoinError> for Error

Available on crate feature tokio-runtime only.
Source§

fn from(value: JoinError) -> Self

Converts to this type from the input type.
Source§

impl From<ParseFloatError> for Error

Source§

fn from(value: ParseFloatError) -> Self

Converts to this type from the input type.
Source§

impl From<ParseIntError> for Error

Source§

fn from(value: ParseIntError) -> Self

Converts to this type from the input type.
Source§

impl From<RecvError> for Error

Source§

fn from(value: RecvError) -> Self

Converts to this type from the input type.
Source§

impl From<RedisError> for Error

Source§

fn from(value: RedisError) -> Self

Converts to this type from the input type.
Source§

impl From<SendError<()>> for Error

Source§

fn from(value: SendError<()>) -> Self

Converts to this type from the input type.
Source§

impl From<SendError> for Error

Source§

fn from(value: SendError) -> Self

Converts to this type from the input type.
Source§

impl From<Utf8Error> for Error

Source§

fn from(value: Utf8Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !Freeze for Error

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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 = !

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

fn try_from(value: U) -> Result<T, !>

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