mpc_relay_server/
error.rs

1use axum::extract::ws::Message;
2use mpc_protocol::{MeetingId, SessionId};
3use std::path::PathBuf;
4use thiserror::Error;
5
6/// Errors generated by the relay server.
7#[derive(Debug, Error)]
8pub enum Error {
9    /// Error generated when a file is expected.
10    #[error(r#"not a file "{0}""#)]
11    NotFile(PathBuf),
12
13    /// Error generated when permission is denied.
14    #[error("permission denied")]
15    PermissionDenied,
16
17    /// Error generated when the config server key file was not specified.
18    #[error("server config requires path to a key file")]
19    KeyFileRequired,
20
21    /// Error generated when the config server key file was not found.
22    #[error(r#"key file "{0}" not found"#)]
23    KeyNotFound(PathBuf),
24
25    /// Error generated attempting to handshake with a peer that
26    /// already exists.
27    #[error("peer already exists")]
28    PeerAlreadyExists,
29
30    /// Error generated when a peer could not be found.
31    #[error(r#"peer "{0}" not found "#)]
32    PeerNotFound(String),
33
34    /// Error generated when a file does not have a parent directory.
35    #[error("no parent directory")]
36    NoParentDir,
37
38    /// Error generated when a participant expects to be in the handshake
39    /// protocol state.
40    #[error("not handshake protocol state")]
41    NotHandshakeState,
42
43    /// Error generated when a meeting could not be found.
44    #[error(r#"meeting "{0}" not found"#)]
45    MeetingNotFound(MeetingId),
46
47    /// Error generated when a participant attempts to join a meeting
48    /// that is full.
49    #[error(r#"meeting "{0}" is full"#)]
50    MeetingFull(MeetingId),
51
52    /// Error generated when a session could not be found.
53    #[error(r#"session "{0}" not found"#)]
54    SessionNotFound(SessionId),
55
56    /// Error generated attempting to relay to a peer in the context
57    /// of a session but the target peer is not a session participant.
58    #[error(r#"session "{0}" does not have participant "{1}""#)]
59    NotSessionParticipant(SessionId, String),
60
61    /// Error generated when the session timeout is not greater
62    /// than the interval.
63    #[error("session timeout must be greater than the interval")]
64    SessionTimeoutConfig,
65
66    /// Error generated when the session wait timeout is not greater
67    /// than the wait interval.
68    #[error(
69        "session wait timeout must be greater than the wait interval"
70    )]
71    SessionWaitConfig,
72
73    /// Error generated by input/output.
74    #[error(transparent)]
75    Io(#[from] std::io::Error),
76
77    /// Error generated by the protocol library.
78    #[error(transparent)]
79    Protocol(#[from] mpc_protocol::Error),
80
81    /// Error generated by the web server library.
82    #[error(transparent)]
83    Axum(#[from] axum::Error),
84
85    /// Error generated by the noise protocol library.
86    #[error(transparent)]
87    Snow(#[from] mpc_protocol::snow::error::Error),
88
89    /// Error generated parsing TOML.
90    #[error(transparent)]
91    Toml(#[from] toml::de::Error),
92
93    /// Error generated when a header value is invalid.
94    #[error(transparent)]
95    HeaderValue(#[from] axum::http::header::InvalidHeaderValue),
96
97    /// Error generated sending a buffer over a channel.
98    #[error(transparent)]
99    BufferMpscSend(
100        #[from] tokio::sync::mpsc::error::SendError<Vec<u8>>,
101    ),
102
103    /// Error generated sending a message over a channel.
104    #[error(transparent)]
105    MessageMpscSend(
106        #[from] tokio::sync::mpsc::error::SendError<Message>,
107    ),
108}