use std::fmt;
pub type SteamResult<T> = Result<T, SteamError>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum SteamError {
#[error("i/o error: {0}")]
Io(#[from] std::io::Error),
#[error("connection error: {0}")]
Connection(String),
#[error("connection closed by peer")]
ConnectionClosed,
#[error("timed out after {0:?}")]
Timeout(std::time::Duration),
#[error("job failed: the request was rejected by the server")]
JobFailed,
#[error("operation was cancelled")]
Cancelled,
#[error("authentication failed: {0}")]
Authentication(String),
#[error("protocol error: {0}")]
Protocol(String),
#[error("malformed message: {0}")]
Malformed(String),
#[error("decompression failed: {0}")]
Decompression(String),
#[error("cryptographic error: {0}")]
Crypto(String),
#[error("invalid argument: {0}")]
InvalidArgument(String),
#[error("not found: {0}")]
NotFound(String),
#[error("json error: {0}")]
Json(#[from] serde_json::Error),
#[error("protobuf decode error: {0}")]
Protobuf(#[from] prost::DecodeError),
#[error("protobuf encode error: {0}")]
ProtobufEncode(#[from] prost::EncodeError),
#[error("{0}")]
Other(String),
}
impl SteamError {
pub fn connection(message: impl fmt::Display) -> Self {
SteamError::Connection(message.to_string())
}
pub fn protocol(message: impl fmt::Display) -> Self {
SteamError::Protocol(message.to_string())
}
pub fn invalid_argument(message: impl fmt::Display) -> Self {
SteamError::InvalidArgument(message.to_string())
}
}