forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.rs
More file actions
55 lines (47 loc) · 1.87 KB
/
error.rs
File metadata and controls
55 lines (47 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! Error returned by the core `Tracker`.
//!
//! Error | Context | Description
//! ---|---|---
//! `PeerKeyNotValid` | Authentication | The supplied key is not valid. It may not be registered or expired.
//! `PeerNotAuthenticated` | Authentication | The peer did not provide the authentication key.
//! `TorrentNotWhitelisted` | Authorization | The action cannot be perform on a not-whitelisted torrent (it only applies for trackers running in `listed` or `private_listed` modes).
//!
use std::panic::Location;
use torrust_tracker_located_error::LocatedError;
use torrust_tracker_primitives::info_hash::InfoHash;
use super::auth::ParseKeyError;
use super::databases;
/// Authentication or authorization error returned by the core `Tracker`
#[derive(thiserror::Error, Debug, Clone)]
pub enum Error {
// Authentication errors
#[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> },
// Authorization errors
#[error("The torrent: {info_hash}, is not whitelisted, {location}")]
TorrentNotWhitelisted {
info_hash: InfoHash,
location: &'static Location<'static>,
},
}
/// Errors related to peers keys.
#[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>,
},
}