Skip to main content

irontide_core/
error.rs

1/// Result type alias for irontide-core operations.
2pub type Result<T> = std::result::Result<T, Error>;
3
4/// Errors from core `BitTorrent` operations.
5#[derive(Debug, thiserror::Error)]
6pub enum Error {
7    /// Bencode parsing error.
8    #[error("bencode: {0}")]
9    Bencode(#[from] irontide_bencode::Error),
10
11    /// Invalid magnet link.
12    #[error("invalid magnet link: {0}")]
13    InvalidMagnet(String),
14
15    /// Invalid hex string.
16    #[error("invalid hex: {0}")]
17    InvalidHex(String),
18
19    /// Invalid hash length.
20    #[error("invalid hash length: expected {expected}, got {got}")]
21    InvalidHashLength {
22        /// Expected byte length.
23        expected: usize,
24        /// Actual byte length received.
25        got: usize,
26    },
27
28    /// Torrent metainfo is malformed.
29    #[error("invalid torrent: {0}")]
30    InvalidTorrent(String),
31
32    /// I/O error.
33    #[error("io: {0}")]
34    Io(#[from] std::io::Error),
35
36    /// Torrent creation error.
37    #[error("create torrent: {0}")]
38    CreateTorrent(String),
39}