Refactor: Extract new crate binstalk-{signal, downloader} (#518)

* Refactor: Extract new crate binstalk-downloader
* Re-export `PkgFmt` from `binstalk_manifests`
* Update release-pr.yml
* Update dependabot

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-11-11 15:02:54 +11:00 committed by GitHub
parent 3841762a5b
commit 89fa5b1769
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 456 additions and 260 deletions

View file

@ -4,6 +4,10 @@ use std::{
process::{ExitCode, ExitStatus, Termination},
};
use binstalk_downloader::{
download::{DownloadError, ZipError},
remote::{Error as RemoteError, HttpError, ReqwestError},
};
use compact_str::CompactString;
use miette::{Diagnostic, Report};
use thiserror::Error;
@ -47,7 +51,7 @@ pub enum BinstallError {
/// - Exit: 66
#[error(transparent)]
#[diagnostic(severity(error), code(binstall::unzip))]
Unzip(#[from] zip::result::ZipError),
Unzip(#[from] ZipError),
/// A rendering error in a template.
///
@ -65,7 +69,7 @@ pub enum BinstallError {
/// - Exit: 68
#[error(transparent)]
#[diagnostic(severity(error), code(binstall::reqwest))]
Reqwest(#[from] reqwest::Error),
Reqwest(#[from] ReqwestError),
/// An HTTP request failed.
///
@ -74,14 +78,9 @@ pub enum BinstallError {
///
/// - Code: `binstall::http`
/// - Exit: 69
#[error("could not {method} {url}")]
#[error(transparent)]
#[diagnostic(severity(error), code(binstall::http))]
Http {
method: reqwest::Method,
url: url::Url,
#[source]
err: reqwest::Error,
},
Http(#[from] HttpError),
/// A subprocess failed.
///
@ -418,3 +417,27 @@ impl From<BinstallError> for io::Error {
}
}
}
impl From<RemoteError> for BinstallError {
fn from(e: RemoteError) -> Self {
use RemoteError::*;
match e {
Reqwest(reqwest_error) => reqwest_error.into(),
Http(http_error) => http_error.into(),
}
}
}
impl From<DownloadError> for BinstallError {
fn from(e: DownloadError) -> Self {
use DownloadError::*;
match e {
Unzip(zip_error) => zip_error.into(),
Remote(remote_error) => remote_error.into(),
Io(io_error) => io_error.into(),
UserAbort => BinstallError::UserAbort,
}
}
}