Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error {
Show 19 variants Closed, NotConnected, AlreadyConnected, NoProtocols, NoTransport, Rejected { key: String, }, Unsubscribed, UnsupportedSubprotocol { negotiated: String, offered: Vec<String>, }, Disconnected { reason: Option<DisconnectReason>, reconnect: bool, }, GaveUp { attempts: u32, last: Box<Error>, }, Stale { after: Duration, }, Handshake { status: StatusCode, }, Close { code: u16, reason: String, }, MessageTooBig { size: usize, limit: usize, }, Transport(Arc<dyn Error + Send + Sync>), Headers(Arc<dyn Error + Send + Sync>), InvalidHeader { name: String, source: Arc<Error>, }, DataNotAnObject { action: String, }, Json(Arc<Error>),
}
Expand description

Everything a caller can get back from a cable. It is Clone because a client that stopped for good hands the same failure to everyone who asks it afterwards.

Which method returns what:

The built-in transport reports three of its failures by name, for a caller that wants to act on them rather than read them: Handshake, Close and MessageTooBig. Anything else a transport hits arrives as Transport, and whatever a HeaderProvider failed on as Headers; both keep the original error, and cause hands it back for an application to recognize with downcast_ref.

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

Closed

The client was closed, or nothing holds it any more. A client that stopped on its own hands out what stopped it instead.

§

NotConnected

A command couldn’t be sent because the connection is down, or up but not yet welcomed. Subscriptions recover on their own; a perform or send that hits this is lost and has to be sent again. subscribe before connect gets it too.

§

AlreadyConnected

connect was called on a client that is already running.

§

NoProtocols

The protocol list was replaced with nothing, so there is nothing to offer the server.

§

NoTransport

No transport was given and the websocket feature that supplies the built-in one is off, so there is nothing to dial with.

§

Rejected

The channel’s subscribed method rejected the subscription. key is the identifier as the server knows it, Identifier::key.

Fields

§key: String

The identifier the server turned down.

§

Unsubscribed

What Subscription::err reports after unsubscribe.

§

UnsupportedSubprotocol

The server negotiated a subprotocol none of the client’s protocols speak, none at all, or the actioncable-unsupported sentinel that says it speaks none of what was offered. Reconnecting won’t fix that, so the client stops.

Fields

§negotiated: String

What the server named, empty when it named nothing.

§offered: Vec<String>

The subprotocols that were offered, most preferred first.

§

Disconnected

The server sent a disconnect frame. reason is None when the frame named none, and reconnect is what the frame said about coming back: the client stops on a disconnect that says not to, and dials again on one that says to.

Fields

§reason: Option<DisconnectReason>

Why the server hung up, as it spelled it.

§reconnect: bool

Whether the server expects the client back.

§

GaveUp

As many connection attempts failed in a row as ClientBuilder::max_attempts allows, so the client stopped. A welcome resets the count, so this bounds one outage rather than the client’s lifetime.

Fields

§attempts: u32

How many attempts failed in a row.

§last: Box<Error>

What the last of them failed on.

§

Stale

The connection went quiet for longer than ClientBuilder::stale_after. The server beats a ping every three seconds, so silence means the connection is dead; it is dropped and redialed.

Fields

§after: Duration

How long the client waited.

§

Handshake

The server answered the upgrade request with something other than 101 Switching Protocols. status tells a redirect from a refusal, and prints as the whole status line.

Fields

§status: StatusCode

What the server answered instead.

§

Close

The server closed the connection with a close frame. code is the status code it carried, 1005 when it carried none, and reason the text after it, if any.

Fields

§code: u16

RFC 6455’s close code.

§reason: String

What the frame said, empty when it said nothing.

§

MessageTooBig

The server sent a message larger than the transport allows. It is refused as soon as its length is known, before any of it is read in, and the connection is failed.

Fields

§size: usize

The size the frame claimed.

§limit: usize

The largest message this transport accepts.

§

Transport(Arc<dyn Error + Send + Sync>)

The transport failed to dial, read or write. A failed dial or read is redialed and only logged; a failed write comes back from the perform, send or unsubscribe that asked for it, and the connection is dropped and redialed.

§

Headers(Arc<dyn Error + Send + Sync>)

The header provider couldn’t produce headers for a dial. That dial is turned down and the client tries again on its backoff.

§

InvalidHeader

A header given to the builder is not a valid HTTP header.

Fields

§name: String

The header that was refused.

§source: Arc<Error>

What http said about it.

§

DataNotAnObject

The data given to perform encodes to something other than a JSON object, which is the only shape Rails will route to an action.

Fields

§action: String

The action the data was for.

§

Json(Arc<Error>)

A message didn’t decode into the type asked for, data for perform or send didn’t encode, or a frame wasn’t the JSON the protocol expects.

Implementations§

Source§

impl Error

Source

pub fn transport(source: impl Error + Send + Sync + 'static) -> Error

Wraps a transport’s own error, for Transport and Conn implementations.

Source

pub fn headers(source: impl Error + Send + Sync + 'static) -> Error

Wraps whatever stopped a HeaderProvider from answering.

Source

pub fn cause(&self) -> Option<&(dyn Error + Send + Sync + 'static)>

The error underneath this one, as the transport or the header provider handed it over, for a caller that wants to recognize its own with downcast_ref:

let error = Error::headers(SignedOut);

assert!(error.cause().is_some_and(|cause| cause.is::<SignedOut>()));

GaveUp hands back what the last attempt failed on, since that is the error the caller was waiting out. Everything else has no error underneath it and answers None.

This is here rather than left to source because the wrapped error is held behind an Arc, and a source walk hands back the Arc rather than what is in it. source still prints the chain; cause is what downcast_ref works on.

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, __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
Source§

impl From<Error> for Error

Source§

fn from(source: Error) -> Error

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Freeze 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> Same for T

Source§

type Output = T

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