Skip to main content

iroh_live_relay/
error.rs

1//! The library's error type.
2
3use std::{path::PathBuf, sync::Arc, time::Duration};
4
5use iroh::EndpointId;
6use moq_net::Path;
7use n0_error::{AnyError, stack_error};
8
9/// An error from running the media relay, pulling a broadcast, or loading a key.
10///
11/// It is cheap to clone, so every session that waits on one pull gets the
12/// same failure. The node's errors sit in a [`Box`], since they are large.
13#[stack_error(derive, add_meta)]
14#[derive(Clone)]
15pub enum Error {
16    /// The ticket's peer may not publish the ticket's path.
17    ///
18    /// The peer does not own the path, already holds too many claims, or the
19    /// media relay's node has shut down.
20    #[error("cannot claim {path} for its publisher")]
21    Claim {
22        path: Path,
23        #[error(source, std_err)]
24        source: Box<iroh_live_node::Error>,
25    },
26    /// The media relay could not reach the ticket's publisher.
27    #[error("failed to reach the publisher {}", peer.fmt_short())]
28    Connect {
29        peer: EndpointId,
30        #[error(source, std_err)]
31        source: Box<iroh_live_node::Error>,
32    },
33    /// The publisher's session did not resolve the ticket's path.
34    #[error("failed to subscribe to {path}")]
35    Subscribe {
36        path: Path,
37        #[error(source, std_err)]
38        source: Box<iroh_live_node::Error>,
39    },
40    /// The publisher did not announce the path in time.
41    #[error("the publisher did not announce {path} within {timeout:?}")]
42    Timeout { path: Path, timeout: Duration },
43    /// The session may not pull: it has no token that grants reading the ticket's path.
44    ///
45    /// See [`Access`](crate::pull::Access).
46    #[error("pulling a ticket through this relay needs a token that grants reading {path}")]
47    PullDenied { path: Path },
48    /// The media relay already holds as many pulls as its limits allow.
49    #[error("the relay already holds its limit of {limit} pulls")]
50    PullLimit { limit: usize },
51    /// The client already holds as many pulls as its limits allow.
52    #[error("this client already holds its limit of {limit} pulls")]
53    ClientPullLimit { limit: usize },
54    /// The client started too many new pulls too recently.
55    #[error("this client started too many pulls recently, try again later")]
56    DialRateLimit,
57    /// The pull ended before its dial reported an outcome.
58    #[error("the pull was dropped before it connected")]
59    Dropped,
60    /// The platform has no data directory to keep the media relay's identity in.
61    #[error("no platform data directory, set IROH_LIVE_RELAY_DATA")]
62    NoDataDir,
63    /// The media relay's identity could not be loaded or stored.
64    #[error(
65        "cannot load the relay's identity. Deleting {} starts over, with a new \
66         endpoint id that invalidates every ticket naming the old one",
67        path.display()
68    )]
69    Identity {
70        path: PathBuf,
71        #[error(source, std_err)]
72        source: Arc<std::io::Error>,
73    },
74    /// The media relay's iroh endpoint could not bind.
75    #[error("the relay's iroh endpoint")]
76    Bind {
77        #[error(source, std_err)]
78        source: Arc<iroh_live_node::EndpointError>,
79    },
80    /// The JWT keys could not be read.
81    #[error("cannot read the JWT keys from {}", path.display())]
82    Keys {
83        path: PathBuf,
84        #[error(source, std_err)]
85        source: Arc<moq_auth::Error>,
86    },
87    /// The media relay failed to start or stopped with an error.
88    #[error("the moq relay failed")]
89    Relay {
90        #[error(source, std_err)]
91        source: Arc<AnyError>,
92    },
93}