Files
soulseek-rs-modded/soulseek-rs-lib/src/error.rs
T
michel e72c8a5c07 style: crank clippy to pedantic+nursery and fix all lints
Enable the full clippy all + pedantic + nursery groups as workspace warnings,
with a small documented allow-list for the pedantic/nursery lints this project
intentionally does not follow (rustdoc-style requirements, deliberate numeric
casts in the protocol/UI layers, and a few noisy nursery lints). Also enable
the rust unused_lifetimes and unsafe_op_in_unsafe_fn lints.

Fixed every resulting warning (527 -> 0) mechanically per clippy's suggestions:
inline format args, const fns, item ordering, let-else, redundant clones,
map_or, cast_lossless, Eq derives, associated-fn conversions for methods that
never used self, and removing unnecessary Result wrappers whose call sites could
never propagate an error. No runtime behavior changed; cargo fmt applied.

cargo clippy --workspace --all-targets: 0 warnings. All tests pass.
2026-07-19 00:09:17 +02:00

80 lines
2.3 KiB
Rust

use std::{error::Error, fmt};
/// Custom error type for the Soulseek download library
#[derive(Debug)]
pub enum SoulseekRs {
NetworkError(std::io::Error),
/// Authentication failed during login
AuthenticationFailed,
/// Error parsing messages or data
ParseError(String),
/// Operation timed out
Timeout,
/// Connection was closed unexpectedly
ConnectionClosed,
/// Invalid message format or content
InvalidMessage(String),
/// Server not connected
NotConnected,
/// Compression/decompression error
CompressionError(String),
/// A lock was poisoned by a panic in another thread
LockPoisoned,
}
impl fmt::Display for SoulseekRs {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NetworkError(err) => {
write!(f, "Network error: {err}")
}
Self::AuthenticationFailed => {
write!(f, "Authentication failed")
}
Self::ParseError(msg) => write!(f, "Parse error: {msg}"),
Self::Timeout => write!(f, "Operation timed out"),
Self::ConnectionClosed => write!(f, "Connection closed"),
Self::InvalidMessage(msg) => {
write!(f, "Invalid message: {msg}")
}
Self::NotConnected => write!(f, "Not connected to server"),
Self::CompressionError(msg) => {
write!(f, "Compression error: {msg}")
}
Self::LockPoisoned => {
write!(f, "Lock poisoned by panicking thread")
}
}
}
}
impl Error for SoulseekRs {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::NetworkError(err) => Some(err),
_ => None,
}
}
}
impl From<std::io::Error> for SoulseekRs {
fn from(err: std::io::Error) -> Self {
Self::NetworkError(err)
}
}
impl From<std::num::ParseIntError> for SoulseekRs {
fn from(err: std::num::ParseIntError) -> Self {
Self::ParseError(format!("Integer parse error: {err}"))
}
}
impl From<String> for SoulseekRs {
fn from(err: String) -> Self {
Self::CompressionError(err)
}
}
/// Result type alias for the Soulseek library
pub type Result<T> = std::result::Result<T, SoulseekRs>;