use std::io;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("io: {0}")]
Io(#[from] io::Error),
#[error("transport: {0}")]
Transport(String),
#[error("peer closed the connection: {0}")]
Closed(String),
#[error("protocol violation: {0}")]
Protocol(String),
#[error("unsupported wire version {peer} (we support {ours})")]
Version { peer: u16, ours: u16 },
#[error("handshake failed: {0}")]
Handshake(String),
#[error("decryption failed for file {file_id} chunk {chunk}")]
Decrypt { file_id: u32, chunk: u64 },
#[error("compression: {0}")]
Compress(String),
#[error("integrity check failed for {path}: expected {expected}, got {actual}")]
Integrity {
path: String,
expected: String,
actual: String,
},
#[error("frame too large: {got} bytes exceeds limit {limit}")]
FrameTooLarge { got: usize, limit: usize },
#[error("configuration: {0}")]
Config(String),
#[error("path {0:?} escapes the destination root")]
UnsafePath(std::path::PathBuf),
#[error("transfer cancelled")]
Cancelled,
#[error("worker panicked: {0}")]
Worker(String),
}
impl Error {
#[allow(dead_code)]
pub(crate) fn transport(e: impl std::fmt::Display) -> Self {
Error::Transport(e.to_string())
}
pub(crate) fn protocol(e: impl Into<String>) -> Self {
Error::Protocol(e.into())
}
}
pub type Result<T> = std::result::Result<T, Error>;