🐛 fix: error handling

Signed-off-by: Pauline <git@ethanlibs.co>
This commit is contained in:
Pauline 2024-08-17 18:58:05 +02:00
parent 27b776a09d
commit c820a57fc5
No known key found for this signature in database
GPG key ID: 722BB181973296AE
5 changed files with 14 additions and 14 deletions

View file

@ -4,6 +4,8 @@ use crate::State;
pub use interpulse::api::minecraft::VersionManifest;
pub use interpulse::api::modded::Manifest;
// TODO: better error handling (prisma?)
/// Get a [`VersionManifest`] for all available Minecraft versions.
#[tracing::instrument]
pub async fn get_minecraft_versions() -> crate::Result<VersionManifest> {

View file

@ -233,9 +233,7 @@ pub async fn generate_pack_from_version_id(
.first()
.map(|file| (file.url.clone(), file.hashes.get("sha1")))
}
.ok_or_else(|| {
crate::ErrorKind::AnyhowError(anyhow::anyhow!("specified version has no files"))
})?;
.ok_or_else(|| { anyhow::anyhow!("specified version has no files") })?;
let file = fetch_advanced(
Method::GET,

View file

@ -96,7 +96,7 @@ pub async fn install_zipped_mrpack_files(
let pack: PackFormat = serde_json::from_str(&manifest)?;
if &*pack.game != "minecraft" {
return Err(anyhow::anyhow!("pack doesn't support minecraft").into());
return Err(anyhow::anyhow!("pack doesn't support Minecraft").into());
}
set_cluster_information(
@ -231,7 +231,7 @@ pub async fn install_zipped_mrpack_files(
Ok::<ClusterPath, crate::Error>(cluster_path.clone())
} else {
Err(anyhow::anyhow!("No pack manifest found in mrpack").into())
Err(anyhow::anyhow!("no pack manifest found in mrpack").into())
}
}
@ -259,7 +259,7 @@ pub async fn remove_all_related_files(
let pack: PackFormat = serde_json::from_str(&manifest)?;
if &*pack.game != "minecraft" {
return Err(anyhow::anyhow!("package doesn't support Minecraft").into());
return Err(anyhow::anyhow!("pack doesn't support Minecraft").into());
}
crate::api::cluster::edit(&cluster_path, |cl| {
@ -292,12 +292,12 @@ pub async fn remove_all_related_files(
.into_values()
.map(|p| p.package_id)
.collect::<Vec<_>>();
let cluster = cluster::get(&cluster_path, None).await?.ok_or_else(|| {
crate::ErrorKind::AnyhowError(anyhow::anyhow!(
let cluster = cluster::get(&cluster_path, None).await?.ok_or_else(||
anyhow::anyhow!(
"{} is an unmanaged cluster!",
cluster_path.to_string()
))
})?;
)
)?;
for (package_id, package) in &cluster.packages {
if let PackageMetadata::Managed { package, .. } = &package.meta {
if to_remove.contains(&package.id) {
@ -338,6 +338,6 @@ pub async fn remove_all_related_files(
}
Ok(())
} else {
Err(anyhow::anyhow!("No pack manifest found in mrpack").into())
Err(anyhow::anyhow!("no pack manifest found in mrpack").into())
}
}

View file

@ -20,7 +20,7 @@ pub async fn set(settings: Settings) -> crate::Result<()> {
let state = State::get().await?;
if settings.config_dir != state.settings.read().await.config_dir {
return Err(anyhow::anyhow!("ccannot change config directory as a setting").into());
return Err(anyhow::anyhow!("cannot change config directory as a setting").into());
}
let (io, fetch) = async {

View file

@ -192,12 +192,12 @@ pub async fn install_minecraft(
false,
)?)
.await?
.ok_or_else(|| {
.ok_or_else(||
anyhow::anyhow!(
"failed to find processor main class for {}",
processor.jar
)
})?,
)?,
)
.args(arguments::processor_arguments(
&libraries,