mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-07 20:50:03 +00:00
Improve GhCrateMeta
: Detect cases where pkg-fmt is not specified (#757)
* Fix fmt of mod `<GhCrateMeta as Fetcher>::find` * Add new variant `BinstallError::InvalidPkgFmt` * Impl new fn `PkgFmt::guess_pkg_format` * Improve `GhCrateMeta`: Detect cases where `pkg-fmt` is not specified but `pkg-url` also does not contain format, archive-format or archive-suffix which is required for automatically deducing the pkg-fmt. In these cases, we would call `PkgFmt::guess_pkg_format` to try out best to figure out the pkg-fmt, otherwise we just return an error. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
5c02581569
commit
e510511487
3 changed files with 98 additions and 14 deletions
|
@ -41,6 +41,16 @@ pub struct CrateContextError {
|
|||
err: BinstallError,
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
#[error("Invalid pkg-url {pkg_url} for {crate_name}@{version} on {target}: {reason}")]
|
||||
pub struct InvalidPkgFmtError {
|
||||
pub crate_name: CompactString,
|
||||
pub version: CompactString,
|
||||
pub target: String,
|
||||
pub pkg_url: String,
|
||||
pub reason: &'static str,
|
||||
}
|
||||
|
||||
/// Error kinds emitted by cargo-binstall.
|
||||
#[derive(Error, Diagnostic, Debug)]
|
||||
#[non_exhaustive]
|
||||
|
@ -291,6 +301,14 @@ pub enum BinstallError {
|
|||
#[diagnostic(severity(error), code(binstall::no_fallback_to_cargo_install))]
|
||||
NoFallbackToCargoInstall,
|
||||
|
||||
/// Fallback to `cargo-install` is disabled.
|
||||
///
|
||||
/// - Code: `binstall::invalid_pkg_fmt`
|
||||
/// - Exit: 95
|
||||
#[error(transparent)]
|
||||
#[diagnostic(severity(error), code(binstall::invalid_pkg_fmt))]
|
||||
InvalidPkgFmt(Box<InvalidPkgFmtError>),
|
||||
|
||||
/// A wrapped error providing the context of which crate the error is about.
|
||||
#[error(transparent)]
|
||||
#[diagnostic(transparent)]
|
||||
|
@ -324,6 +342,7 @@ impl BinstallError {
|
|||
InvalidSourceFilePath { .. } => 91,
|
||||
EmptySourceFilePath => 92,
|
||||
NoFallbackToCargoInstall => 94,
|
||||
InvalidPkgFmt(..) => 95,
|
||||
CrateContext(context) => context.err.exit_number(),
|
||||
};
|
||||
|
||||
|
@ -428,3 +447,9 @@ impl From<CargoTomlError> for BinstallError {
|
|||
BinstallError::CargoManifest(Box::new(e))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InvalidPkgFmtError> for BinstallError {
|
||||
fn from(e: InvalidPkgFmtError) -> Self {
|
||||
BinstallError::InvalidPkgFmt(Box::new(e))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue