pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("wire: {0}")]
Wire(#[from] irontide_wire::Error),
#[error("storage: {0}")]
Storage(#[from] irontide_storage::Error),
#[error("tracker: {0}")]
Tracker(#[from] irontide_tracker::Error),
#[error("DHT: {0}")]
Dht(#[from] irontide_dht::Error),
#[error("core: {0}")]
Core(#[from] irontide_core::Error),
#[error("connection: {0}")]
Connection(
String,
),
#[error("metadata info_hash mismatch")]
MetadataHashMismatch,
#[error("piece {index} hash verification failed")]
PieceHashFailed {
index: u32,
},
#[error("invalid peer data: {0}")]
InvalidPeerData(
String,
),
#[error("torrent not found: {0}")]
TorrentNotFound(
irontide_core::Id20,
),
#[error("duplicate torrent: {0}")]
DuplicateTorrent(
irontide_core::Id20,
),
#[error("session at capacity ({0} torrents)")]
SessionAtCapacity(
usize,
),
#[error("metadata not yet available for {0}")]
MetadataNotReady(
irontide_core::Id20,
),
#[error("file index {index} out of range (torrent has {count} files)")]
InvalidFileIndex {
index: usize,
count: usize,
},
#[error("file has Skip priority (index {index})")]
FileSkipped {
index: usize,
},
#[error("piece index {index} out of range (torrent has {num_pieces} pieces)")]
InvalidPieceIndex {
index: u32,
num_pieces: u32,
},
#[error("configuration error: {0}")]
Config(
String,
),
#[error("invalid settings: {0}")]
InvalidSettings(
String,
),
#[error("session shutting down")]
Shutdown,
#[error("DHT is disabled")]
DhtDisabled,
#[error("peer read timeout ({0}s)")]
PeerReadTimeout(
u64,
),
#[error("peer data timeout ({0}s)")]
PeerDataTimeout(
u64,
),
#[error("peer write timeout ({0}s)")]
PeerWriteTimeout(
u64,
),
#[error("peer backpressure overflow ({0})")]
PeerBackpressureOverflow(
&'static str,
),
#[error("I2P: {0}")]
I2p(#[from] crate::i2p::SamError),
#[error("I/O: {0}")]
Io(#[from] std::io::Error),
#[error("category not found: {0}")]
CategoryNotFound(
String,
),
#[error("torrent is being removed, retry later")]
TorrentBeingRemoved(
irontide_core::Id20,
),
#[error("category registry: {0}")]
CategoryRegistry(
String,
),
#[error("apply_settings: concurrent reconfig in flight, retry shortly")]
ConcurrentReconfig,
}
impl From<irontide_settings::SettingsError> for Error {
fn from(e: irontide_settings::SettingsError) -> Self {
match e {
irontide_settings::SettingsError::Invalid(msg) => Self::InvalidSettings(msg),
}
}
}
impl From<irontide_peer_io::PeerIoError> for Error {
fn from(e: irontide_peer_io::PeerIoError) -> Self {
match e {
irontide_peer_io::PeerIoError::WriteTimeout(secs) => Self::PeerWriteTimeout(secs),
irontide_peer_io::PeerIoError::Io(io) => Self::Io(io),
}
}
}