torrust_tracker/core/
error.rs

1//! Error returned by the core `Tracker`.
2//!
3//! Error | Context | Description
4//! ---|---|---
5//! `PeerKeyNotValid` | Authentication | The supplied key is not valid. It may not be registered or expired.
6//! `PeerNotAuthenticated` | Authentication | The peer did not provide the authentication key.
7//! `TorrentNotWhitelisted` | Authorization | The action cannot be perform on a not-whitelisted torrent (it only applies for trackers running in `listed` or `private_listed` modes).
8//!
9use std::panic::Location;
10
11use torrust_tracker_located_error::LocatedError;
12use torrust_tracker_primitives::info_hash::InfoHash;
13
14use super::auth::ParseKeyError;
15use super::databases;
16
17/// Authentication or authorization error returned by the core `Tracker`
18#[derive(thiserror::Error, Debug, Clone)]
19pub enum Error {
20    // Authentication errors
21    #[error("The supplied key: {key:?}, is not valid: {source}")]
22    PeerKeyNotValid {
23        key: super::auth::Key,
24        source: LocatedError<'static, dyn std::error::Error + Send + Sync>,
25    },
26
27    #[error("The peer is not authenticated, {location}")]
28    PeerNotAuthenticated { location: &'static Location<'static> },
29
30    // Authorization errors
31    #[error("The torrent: {info_hash}, is not whitelisted, {location}")]
32    TorrentNotWhitelisted {
33        info_hash: InfoHash,
34        location: &'static Location<'static>,
35    },
36}
37
38/// Errors related to peers keys.
39#[allow(clippy::module_name_repetitions)]
40#[derive(thiserror::Error, Debug, Clone)]
41pub enum PeerKeyError {
42    #[error("Invalid peer key duration: {seconds_valid:?}, is not valid")]
43    DurationOverflow { seconds_valid: u64 },
44
45    #[error("Invalid key: {key}")]
46    InvalidKey {
47        key: String,
48        source: LocatedError<'static, ParseKeyError>,
49    },
50
51    #[error("Can't persist key: {source}")]
52    DatabaseError {
53        source: LocatedError<'static, databases::error::Error>,
54    },
55}