irontide_storage/error.rs
1/// Crate-level result type.
2pub type Result<T> = std::result::Result<T, Error>;
3
4/// Errors from torrent storage operations.
5#[derive(Debug, thiserror::Error)]
6pub enum Error {
7 /// Piece index exceeds the torrent's piece count.
8 #[error("piece index {index} out of range (num_pieces: {num_pieces})")]
9 PieceOutOfRange {
10 /// Requested piece index.
11 index: u32,
12 /// Total number of pieces in the torrent.
13 num_pieces: u32,
14 },
15
16 /// Chunk position or length falls outside the piece.
17 #[error("chunk out of range: piece {piece}, begin {begin}, length {length}")]
18 ChunkOutOfRange {
19 /// Piece index.
20 piece: u32,
21 /// Byte offset within the piece.
22 begin: u32,
23 /// Chunk length in bytes.
24 length: u32,
25 },
26
27 /// Bitfield byte count does not match the expected piece count.
28 #[error("invalid bitfield length: expected {expected} bytes, got {got}")]
29 InvalidBitfieldLength {
30 /// Expected byte count.
31 expected: usize,
32 /// Actual byte count.
33 got: usize,
34 },
35
36 /// Spare bits after the last piece are set (malformed bitfield).
37 #[error("trailing bits set in bitfield")]
38 TrailingBitsSet,
39
40 /// I/O error from the underlying storage.
41 #[error("I/O: {0}")]
42 Io(#[from] std::io::Error),
43}