Skip to main content

rift_torrent/
error.rs

1//! Error types for rift-torrent.
2
3use thiserror::Error;
4
5/// Errors that can occur in rift-torrent operations.
6#[derive(Error, Debug)]
7pub enum TorrentError {
8    /// Bencode parsing/encoding errors.
9    #[error("bencode error: {0}")]
10    Bencode(String),
11
12    /// Invalid .torrent file structure.
13    #[error("invalid torrent file: {0}")]
14    InvalidTorrent(&'static str),
15
16    /// Magnet URI parsing errors.
17    #[error("invalid magnet uri: {0}")]
18    InvalidMagnet(&'static str),
19
20    /// SRT parsing or derivation errors.
21    #[error("srt error: {0}")]
22    Srt(String),
23
24    /// I/O errors (file operations).
25    #[error("io error: {0}")]
26    Io(#[from] std::io::Error),
27
28    /// Peer discovery failed.
29    #[error("peer discovery failed: {0}")]
30    Discovery(String),
31
32    /// Piece verification failed.
33    #[error("piece hash mismatch at index {0}")]
34    PieceHashMismatch(u32),
35
36    /// Infohash derivation error.
37    #[error("infohash error: {0}")]
38    InfoHash(&'static str),
39
40    /// URL encoding/decoding error.
41    #[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}