forked from
microcosm.blue/microcosm-rs
Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm
1//! Various error types.
2use std::io;
3
4use thiserror::Error;
5
6/// Possible errors that can occur when a [JetstreamConfig](crate::JetstreamConfig) that is passed
7/// to a [JetstreamConnector](crate::JetstreamConnector) is invalid.
8#[derive(Error, Debug)]
9pub enum ConfigValidationError {
10 #[error("too many wanted collections: {0} > 100")]
11 TooManyWantedCollections(usize),
12 #[error("too many wanted DIDs: {0} > 10,000")]
13 TooManyDids(usize),
14 #[error("invalid endpoint: {0}")]
15 InvalidEndpoint(#[from] url::ParseError),
16}
17
18/// Possible errors that can occur in the process of connecting to a Jetstream instance over
19/// WebSockets.
20///
21/// See [JetstreamConnector::connect](crate::JetstreamConnector::connect).
22#[derive(Error, Debug)]
23pub enum ConnectionError {
24 #[error("invalid endpoint: {0}")]
25 InvalidEndpoint(#[from] url::ParseError),
26 #[error("failed to construct url: {0}")]
27 InvalidEndpointUri(#[from] tokio_tungstenite::tungstenite::http::uri::InvalidUri),
28 #[error("failed to connect to Jetstream instance: {0}")]
29 WebSocketFailure(#[from] tokio_tungstenite::tungstenite::Error),
30 #[error("the Jetstream config is invalid (this really should not happen here): {0}")]
31 InvalidConfig(#[from] ConfigValidationError),
32}
33
34/// Possible errors that can occur when receiving events from a Jetstream instance over WebSockets.
35///
36/// See [websocket_task](crate::websocket_task).
37#[derive(Error, Debug)]
38pub enum JetstreamEventError {
39 #[error("failed to load built-in zstd dictionary for decoding: {0}")]
40 CompressionDictionaryError(io::Error),
41 #[error("failed to send ping or pong: {0}")]
42 PingPongError(#[from] tokio_tungstenite::tungstenite::Error),
43 #[error("no messages received within ttl")]
44 NoMessagesReceived,
45 #[error("jetstream event receiver closed")]
46 ReceiverClosedError,
47}