From c33c803fcff9399e093e236110d87b6e50549b76 Mon Sep 17 00:00:00 2001 From: kawaiinekololis Date: Tue, 12 Dec 2023 10:58:47 +0100 Subject: [PATCH] added error context to version manifest fetch --- src-tauri/src/minecraft/prelauncher.rs | 2 +- src-tauri/src/minecraft/version.rs | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/minecraft/prelauncher.rs b/src-tauri/src/minecraft/prelauncher.rs index 7abbe34..d004b16 100644 --- a/src-tauri/src/minecraft/prelauncher.rs +++ b/src-tauri/src/minecraft/prelauncher.rs @@ -22,7 +22,7 @@ use crate::utils::{download_file, get_maven_artifact_path}; /// pub(crate) async fn launch(launch_manifest: LaunchManifest, launching_parameter: LaunchingParameter, additional_mods: Vec, progress: LauncherData, window: Arc>) -> Result<()> { info!("Loading minecraft version manifest..."); - let mc_version_manifest = VersionManifest::download().await?; + let mc_version_manifest = VersionManifest::fetch().await?; let build = &launch_manifest.build; let subsystem = &launch_manifest.subsystem; diff --git a/src-tauri/src/minecraft/version.rs b/src-tauri/src/minecraft/version.rs index 1024288..50d56c6 100644 --- a/src-tauri/src/minecraft/version.rs +++ b/src-tauri/src/minecraft/version.rs @@ -1,6 +1,6 @@ use std::{collections::HashMap, fmt, marker::PhantomData, path::{Path, PathBuf}, str::FromStr}; -use anyhow::Result; +use anyhow::{Result, Context}; use tracing::{debug, info}; use tokio::fs; use serde::{Deserialize, Deserializer, de::{self, MapAccess, Visitor}}; @@ -21,11 +21,14 @@ pub struct VersionManifest { impl VersionManifest { - pub async fn download() -> Result { + pub async fn fetch() -> Result { let response = HTTP_CLIENT.get("https://launchermeta.mojang.com/mc/game/version_manifest.json") - .send().await? - .error_for_status()?; - let manifest = response.json::().await?; + .send().await + .context("Connection to https://launchermeta.mojang.com/ failed. Check your internet connection.")? + .error_for_status() + .context("https://launchermeta.mojang.com/ returned with an error code, try again later!")?; + let manifest = response.json::().await + .context("Failed to parse Version Manifest, Mojang Server responded with not valid format.")?; Ok(manifest) }