use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("unsupported platform: os={os} arch={arch}")]
UnsupportedPlatform {
os: String,
arch: String,
},
#[error("unknown platform slug: {0}")]
UnknownPlatformSlug(String),
#[error("{context}: {source}")]
Io {
context: String,
#[source]
source: std::io::Error,
},
#[error("HTTP error: {0}")]
Http(#[source] reqwest::Error),
#[error("HTTP {status} when fetching {url}")]
HttpStatus {
url: String,
status: u16,
},
#[error("curl exited with code {code} when fetching {url}")]
CurlFailed {
url: String,
code: i32,
},
#[error("sha256 mismatch: expected {expected}, got {actual}")]
ChecksumMismatch {
expected: String,
actual: String,
},
#[error("failed to parse version TOML: {0}")]
TomlParse(#[source] toml::de::Error),
#[error("zip error: {0}")]
Zip(#[source] zip::result::ZipError),
#[error("hyperd executable not found in extracted archive")]
HyperdNotInArchive,
#[error("failed to scrape latest release: {0}")]
ScrapeFailed(&'static str),
}
impl Error {
pub fn unsupported_platform(os: impl Into<String>, arch: impl Into<String>) -> Self {
Error::UnsupportedPlatform {
os: os.into(),
arch: arch.into(),
}
}
pub fn unknown_platform_slug(slug: impl Into<String>) -> Self {
Error::UnknownPlatformSlug(slug.into())
}
pub fn io(context: impl Into<String>, source: std::io::Error) -> Self {
Error::Io {
context: context.into(),
source,
}
}
pub fn http_status(url: impl Into<String>, status: u16) -> Self {
Error::HttpStatus {
url: url.into(),
status,
}
}
pub fn curl_failed(url: impl Into<String>, code: i32) -> Self {
Error::CurlFailed {
url: url.into(),
code,
}
}
pub fn checksum_mismatch(expected: impl Into<String>, actual: impl Into<String>) -> Self {
Error::ChecksumMismatch {
expected: expected.into(),
actual: actual.into(),
}
}
}