1use std::fmt;
4
5pub type SteamResult<T> = Result<T, SteamError>;
7
8#[derive(Debug, thiserror::Error)]
10#[non_exhaustive]
11pub enum SteamError {
12 #[error("i/o error: {0}")]
14 Io(#[from] std::io::Error),
15
16 #[error("connection error: {0}")]
18 Connection(String),
19
20 #[error("connection closed by peer")]
22 ConnectionClosed,
23
24 #[error("timed out after {0:?}")]
26 Timeout(std::time::Duration),
27
28 #[error("job failed: the request was rejected by the server")]
30 JobFailed,
31
32 #[error("operation was cancelled")]
34 Cancelled,
35
36 #[error("authentication failed: {0}")]
38 Authentication(String),
39
40 #[error("protocol error: {0}")]
42 Protocol(String),
43
44 #[error("malformed message: {0}")]
46 Malformed(String),
47
48 #[error("decompression failed: {0}")]
50 Decompression(String),
51
52 #[error("cryptographic error: {0}")]
54 Crypto(String),
55
56 #[error("invalid argument: {0}")]
58 InvalidArgument(String),
59
60 #[error("not found: {0}")]
62 NotFound(String),
63
64 #[error("json error: {0}")]
66 Json(#[from] serde_json::Error),
67
68 #[error("protobuf decode error: {0}")]
70 Protobuf(#[from] prost::DecodeError),
71
72 #[error("protobuf encode error: {0}")]
74 ProtobufEncode(#[from] prost::EncodeError),
75
76 #[error("{0}")]
78 Other(String),
79}
80
81impl SteamError {
82 pub fn connection(message: impl fmt::Display) -> Self {
84 SteamError::Connection(message.to_string())
85 }
86
87 pub fn protocol(message: impl fmt::Display) -> Self {
89 SteamError::Protocol(message.to_string())
90 }
91
92 pub fn invalid_argument(message: impl fmt::Display) -> Self {
94 SteamError::InvalidArgument(message.to_string())
95 }
96}