#[non_exhaustive]pub enum Error {
Config(ConfigError),
Session(ServerError),
Request(ServerError),
ReconnectExhausted {
attempts: u32,
last: Option<Box<DisconnectReason>>,
},
Disconnected,
Transport(TransportError),
ForeignSubscription {
id: u64,
},
Internal {
reason: String,
},
}Expand description
Anything that can go wrong in a Lightstreamer client.
The variants are grouped by what a caller can do about them:
Error::Config— fix the configuration; nothing was sent.Error::Session,Error::Request— the server said no, and told you why with a code. Branch on the code.Error::ReconnectExhausted— the connection kept failing and this crate has stopped trying. Build a new client when you want to try again.Error::Disconnected— the client is shut down. Nothing is wrong; it is simply over.Error::Transport— bytes could not be moved. Usually a network or TLS problem.Error::ForeignSubscription— a handle from another client. Nothing was sent.Error::Internal— a bug in this crate. Please report it.
§Which of these this crate returns, and which you construct
Everything above is returned by some call, except one:
Error::Request is the way to propagate a refusal that arrived as an
event. A refused control request is not the return value of anything —
it reaches you as SessionEvent::RequestRejected or
SubscriptionEvent::Rejected, because it
happens long after the call that caused it returned. Wrapping the
ServerError it carries in Error::Request is what lets an application
hand it to ? alongside the errors this crate returns, and
ClosedReason::into_error does the same
for the session-level events.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Config(ConfigError)
A configuration value could not be used as given. Nothing was sent to any server.
Session(ServerError)
The server refused to create or bind the session, or ended one that was
running, with a code from Appendix A
[docs/spec/05-error-codes.md §2].
This crate reached this error only after deciding the code admits no retry — for the codes the specification marks as temporary it keeps trying, and you learn about that through the session event stream instead.
Request(ServerError)
The server refused a control request — a subscription, an
unsubscription, a reconfiguration or a message — with a code from
Appendix B [docs/spec/05-error-codes.md §2].
The session itself is unaffected and remains usable.
ReconnectExhausted
The connection kept failing and the reconnection budget ran out. The session is definitively lost and this client will not try again.
The budget is RetryPolicy; raise it, or set it
to unlimited, if giving up is not what you want.
Fields
last: Option<Box<DisconnectReason>>Why the last attempt failed, when there was one to report.
Kept because the count on its own is not diagnosable: “eight
attempts failed” is the same sentence whether the credentials were
refused, the host did not resolve, or the connection kept going
silent. Boxed only to keep Error small.
Disconnected
The client is no longer connected, because it was disconnected or dropped.
Not a failure in itself: it is what every pending operation returns once the session has stopped.
Transport(TransportError)
Something went wrong moving bytes — connecting, sending, or receiving.
ForeignSubscription
A SubscriptionId created by a different
client was passed to
Client::unsubscribe.
Nothing was sent. Each client numbers its subscriptions from one, so the same number names a different subscription on each of them; acting on it would have cancelled somebody else’s data.
Fields
id: u64The number the handle carried, as
SubscriptionId::get reports it.
Internal
This crate could not do something it should always be able to do.
A bug, never a server condition or a configuration mistake.
Implementations§
Source§impl Error
impl Error
Sourcepub const fn server_error(&self) -> Option<&ServerError>
pub const fn server_error(&self) -> Option<&ServerError>
The server’s code and message, when the server supplied one.
A convenience for the common “log the code, then decide” shape. Use the variant itself when you need to know which catalog the code came from.
§Examples
use lightstreamer_rs::{Error, ServerError};
let error = Error::Request(ServerError::new(19, "Specified subscription not found"));
assert_eq!(error.server_error().map(ServerError::code), Some(19));
assert!(Error::Disconnected.server_error().is_none());Sourcepub const fn is_session_terminal(&self) -> bool
pub const fn is_session_terminal(&self) -> bool
Whether the session behind this error is gone for good.
True for a server-side refusal, an exhausted reconnection budget and a disconnected client; false for a rejected control request, which leaves the session running, and for a configuration mistake, which never reached a server.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()