2019-05-24 10:25:55 +02:00
|
|
|
use crate::common::*;
|
|
|
|
|
|
|
|
use structopt::clap;
|
|
|
|
|
|
|
|
#[derive(Debug, Snafu)]
|
|
|
|
#[snafu(visibility(pub(crate)))]
|
|
|
|
pub(crate) enum Error {
|
2020-01-30 14:54:08 +01:00
|
|
|
#[snafu(display("Must provide at least one announce URL"))]
|
|
|
|
AnnounceEmpty,
|
|
|
|
#[snafu(display("Failed to parse announce URL: {}", source))]
|
|
|
|
AnnounceUrlParse { source: url::ParseError },
|
|
|
|
#[snafu(display("Failed to decode bencode: {}", source))]
|
|
|
|
BencodeDecode { source: serde_bencode::Error },
|
2020-02-01 21:30:35 +01:00
|
|
|
#[snafu(display("Failed to parse byte count `{}`: {}", text, source))]
|
|
|
|
ByteParse {
|
|
|
|
text: String,
|
|
|
|
source: ParseFloatError,
|
|
|
|
},
|
|
|
|
#[snafu(display("Failed to parse byte count `{}`, invalid suffix: `{}`", text, suffix))]
|
|
|
|
ByteSuffix { text: String, suffix: String },
|
2019-05-24 10:25:55 +02:00
|
|
|
#[snafu(display("{}", source))]
|
|
|
|
Clap { source: clap::Error },
|
2020-01-30 14:54:08 +01:00
|
|
|
#[snafu(display("Failed to invoke command `{}`: {}", command, source,))]
|
|
|
|
CommandInvoke { command: String, source: io::Error },
|
|
|
|
#[snafu(display("Command `{}` returned bad exit status: {}", command, status))]
|
|
|
|
CommandStatus { command: String, status: ExitStatus },
|
|
|
|
#[snafu(display("Filename was not valid unicode: {}", filename.to_string_lossy()))]
|
|
|
|
FilenameDecode { filename: OsString },
|
|
|
|
#[snafu(display("Path had no file name: {}", path.display()))]
|
|
|
|
FilenameExtract { path: PathBuf },
|
2019-05-24 10:25:55 +02:00
|
|
|
#[snafu(display("I/O error at `{}`: {}", path.display(), source))]
|
|
|
|
Filesystem { source: io::Error, path: PathBuf },
|
2020-01-30 14:54:08 +01:00
|
|
|
#[snafu(display("Failed to find opener utility, please install one of {}", tried.join(",")))]
|
|
|
|
OpenerMissing { tried: &'static [&'static str] },
|
2020-02-01 21:30:35 +01:00
|
|
|
#[snafu(display(
|
|
|
|
"Piece length `{}` too large. The maximum supported piece length is {}.",
|
|
|
|
bytes,
|
|
|
|
Bytes(u32::max_value().into())
|
|
|
|
))]
|
|
|
|
PieceLength { bytes: Bytes },
|
2020-01-30 14:54:08 +01:00
|
|
|
#[snafu(display("Serialization failed: {}", source))]
|
|
|
|
Serialize { source: serde_bencode::Error },
|
2020-01-14 09:52:27 +01:00
|
|
|
#[snafu(display("Failed to write to standard error: {}", source))]
|
2020-01-05 03:58:42 +01:00
|
|
|
Stderr { source: io::Error },
|
2020-01-14 09:52:27 +01:00
|
|
|
#[snafu(display("Failed to write to standard output: {}", source))]
|
|
|
|
Stdout { source: io::Error },
|
2019-05-24 10:25:55 +02:00
|
|
|
#[snafu(display("Failed to retrieve system time: {}", source))]
|
|
|
|
SystemTime { source: SystemTimeError },
|
|
|
|
#[snafu(display(
|
|
|
|
"Feature `{}` cannot be used without passing the `--unstable` flag",
|
|
|
|
feature
|
|
|
|
))]
|
|
|
|
Unstable { feature: &'static str },
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<clap::Error> for Error {
|
2020-01-05 03:58:42 +01:00
|
|
|
fn from(source: clap::Error) -> Self {
|
|
|
|
Self::Clap { source }
|
2019-05-24 10:25:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<serde_bencode::Error> for Error {
|
2020-01-05 03:58:42 +01:00
|
|
|
fn from(source: serde_bencode::Error) -> Self {
|
|
|
|
Self::Serialize { source }
|
2019-05-24 10:25:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<SystemTimeError> for Error {
|
2020-01-05 03:58:42 +01:00
|
|
|
fn from(source: SystemTimeError) -> Self {
|
|
|
|
Self::SystemTime { source }
|
2019-05-24 10:25:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<walkdir::Error> for Error {
|
2020-01-05 03:58:42 +01:00
|
|
|
fn from(walkdir_error: walkdir::Error) -> Self {
|
2019-05-24 10:25:55 +02:00
|
|
|
let path = walkdir_error.path().unwrap().to_owned();
|
|
|
|
|
|
|
|
if let Some(source) = walkdir_error.into_io_error() {
|
2020-01-05 03:58:42 +01:00
|
|
|
Self::Filesystem { source, path }
|
2019-05-24 10:25:55 +02:00
|
|
|
} else {
|
|
|
|
unreachable!("Encountered unexpected walkdir error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|