1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum TorrentError {
8 #[error("bencode error: {0}")]
10 Bencode(String),
11
12 #[error("invalid torrent file: {0}")]
14 InvalidTorrent(&'static str),
15
16 #[error("invalid magnet uri: {0}")]
18 InvalidMagnet(&'static str),
19
20 #[error("srt error: {0}")]
22 Srt(String),
23
24 #[error("io error: {0}")]
26 Io(#[from] std::io::Error),
27
28 #[error("peer discovery failed: {0}")]
30 Discovery(String),
31
32 #[error("piece hash mismatch at index {0}")]
34 PieceHashMismatch(u32),
35
36 #[error("infohash error: {0}")]
38 InfoHash(&'static str),
39
40 #[error("url encoding error: {0}")]
42 UrlEncoding(String),
43}
44
45impl From<hex::FromHexError> for TorrentError {
46 fn from(_: hex::FromHexError) -> Self {
47 TorrentError::InfoHash("invalid hex encoding")
48 }
49}