use std::panic::Location;
use torrust_tracker_located_error::LocatedError;
use torrust_tracker_primitives::info_hash::InfoHash;
use super::auth::ParseKeyError;
use super::databases;
#[derive(thiserror::Error, Debug, Clone)]
pub enum Error {
#[error("The supplied key: {key:?}, is not valid: {source}")]
PeerKeyNotValid {
key: super::auth::Key,
source: LocatedError<'static, dyn std::error::Error + Send + Sync>,
},
#[error("The peer is not authenticated, {location}")]
PeerNotAuthenticated { location: &'static Location<'static> },
#[error("The torrent: {info_hash}, is not whitelisted, {location}")]
TorrentNotWhitelisted {
info_hash: InfoHash,
location: &'static Location<'static>,
},
}
#[allow(clippy::module_name_repetitions)]
#[derive(thiserror::Error, Debug, Clone)]
pub enum PeerKeyError {
#[error("Invalid peer key duration: {seconds_valid:?}, is not valid")]
DurationOverflow { seconds_valid: u64 },
#[error("Invalid key: {key}")]
InvalidKey {
key: String,
source: LocatedError<'static, ParseKeyError>,
},
#[error("Can't persist key: {source}")]
DatabaseError {
source: LocatedError<'static, databases::error::Error>,
},
}