Skip to main content

ruststream_sea_file/
error.rs

1//! The crate-level error type.
2
3use std::error::Error as StdError;
4
5/// Errors returned by the file and stdio transports.
6///
7/// One enum for the whole crate, variants by source, per the `RustStream` broker conventions.
8/// The wrapped sources are boxed `std` errors so the public API does not leak the client's
9/// error types.
10#[derive(Debug, thiserror::Error)]
11#[non_exhaustive]
12pub enum SeaFileError {
13    /// Opening (or creating) the stream file, or attaching stdio, failed.
14    #[error("stream connect error on '{target}': {source}")]
15    Connect {
16        /// The file path or `stdio`.
17        target: String,
18        /// The client's failure.
19        #[source]
20        source: Box<dyn StdError + Send + Sync>,
21    },
22
23    /// Opening a subscription failed.
24    #[error("subscribe error on '{stream}': {source}")]
25    Subscribe {
26        /// The stream key the subscription targeted.
27        stream: String,
28        /// The client's failure.
29        #[source]
30        source: Box<dyn StdError + Send + Sync>,
31    },
32
33    /// The transport failed while receiving.
34    #[error("receive error on '{stream}': {source}")]
35    Receive {
36        /// The stream key (or file) of the subscription.
37        stream: String,
38        /// The client's failure.
39        #[source]
40        source: Box<dyn StdError + Send + Sync>,
41    },
42
43    /// Publishing failed.
44    #[error("publish error to '{stream}': {source}")]
45    Publish {
46        /// The stream key the message targeted.
47        stream: String,
48        /// The client's failure.
49        #[source]
50        source: Box<dyn StdError + Send + Sync>,
51    },
52
53    /// Repositioning failed.
54    #[error("seek error on '{stream}': {source}")]
55    Seek {
56        /// The stream key of the subscription.
57        stream: String,
58        /// The client's failure.
59        #[source]
60        source: Box<dyn StdError + Send + Sync>,
61    },
62
63    /// The handle is used before `connect` filled the shared state, or after `shutdown`.
64    #[error("stream transport is not connected")]
65    NotConnected,
66
67    /// A descriptor or payload is invalid for this transport.
68    #[error("invalid descriptor: {0}")]
69    Invalid(String),
70}
71
72/// Boxes a client error into the crate's `Box<dyn StdError>` source form.
73pub(crate) fn box_err<E>(err: E) -> Box<dyn StdError + Send + Sync>
74where
75    E: StdError + Send + Sync + 'static,
76{
77    Box::new(err)
78}