use std::fmt;
#[derive(Debug)]
#[non_exhaustive]
pub enum I2pError {
AlreadyRunning,
InvalidAppName,
WorkerPanicked,
DestinationCreationFailed,
KeyGenerationFailed,
ConnectFailed,
DestinationClosed,
Io(std::io::Error),
}
impl fmt::Display for I2pError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::AlreadyRunning => f.write_str("an I2pRouter is already running in this process"),
Self::InvalidAppName => f.write_str("application name contains an interior NUL byte"),
Self::WorkerPanicked => f.write_str("internal blocking worker task panicked"),
Self::DestinationCreationFailed => {
f.write_str("libi2pd failed to create the destination")
}
Self::KeyGenerationFailed => {
f.write_str("libi2pd failed to generate a destination keypair")
}
Self::ConnectFailed => f.write_str("failed to connect to the remote I2P destination"),
Self::DestinationClosed => f.write_str("the destination was closed"),
Self::Io(e) => write!(f, "I/O error: {e}"),
}
}
}
impl std::error::Error for I2pError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Io(e) => Some(e),
_ => None,
}
}
}