chore: improve rmcl diagnostic logging

This commit is contained in:
objz committed 2026-06-16 10:22:51 +02:00
1 parent a58e6fb76d
commit 09bc8f26fb
23 files changed
+925 -61

No files matched your search

+27 -1
View File
@@ -56,7 +56,9 @@ pub async fn fetch_fabric_game_versions_from(
meta_base: &str,
) -> Result<Vec<GameVersion>, NetError> {
let url = format!("{}/versions/game", meta_base);
tracing::debug!("Fetching Fabric game versions from {}", url);
let versions: Vec<FabricGameVersion> = client.get_json(&url).await?;
tracing::debug!("Fetched {} Fabric game version(s)", versions.len());
Ok(versions
.into_iter()
@@ -80,7 +82,14 @@ pub async fn fetch_fabric_versions_from(
game_version: &str,
) -> Result<Vec<FabricLoaderVersion>, NetError> {
let url = format!("{}/versions/loader/{}", meta_base, game_version);
client.get_json(&url).await
tracing::debug!("Fetching Fabric loader versions for {}", game_version);
let versions: Vec<FabricLoaderVersion> = client.get_json(&url).await?;
tracing::debug!(
"Fetched {} Fabric loader version(s) for {}",
versions.len(),
game_version
);
Ok(versions)
}
pub async fn fetch_fabric_profile(
@@ -101,6 +110,11 @@ pub async fn fetch_fabric_profile_from(
"{}/versions/loader/{}/{}/profile/json",
meta_base, game_version, loader_version
);
tracing::debug!(
"Fetching Fabric profile for Minecraft {} loader {}",
game_version,
loader_version
);
client.get_json(&url).await
}
@@ -126,6 +140,11 @@ pub async fn fetch_fabric_profile_with_raw_from(
"{}/versions/loader/{}/{}/profile/json",
meta_base, game_version, loader_version
);
tracing::debug!(
"Fetching raw Fabric profile for Minecraft {} loader {}",
game_version,
loader_version
);
client.get_json_with_raw(&url, "Fabric profile").await
}
@@ -137,6 +156,11 @@ pub async fn download_fabric_libraries(
meta_dir: &Path,
) -> Result<(), NetError> {
let libraries_dir = meta_dir.join("libraries");
tracing::debug!(
"Resolving {} Fabric libraries into {}",
profile.libraries.len(),
libraries_dir.display()
);
for lib in &profile.libraries {
let maven_path = match crate::net::maven_coord_to_path(&lib.name) {
@@ -161,10 +185,12 @@ pub async fn download_fabric_libraries(
set_sub_action(&lib.name);
tracing::info!("Downloading Fabric library: {}", lib.name);
tracing::trace!("Fabric library destination: {}", dest.display());
download_file(client, &download_url, &dest, |_, _| {}).await?;
}
tracing::debug!("Fabric library resolution complete for {}", profile.id);
Ok(())
}
+43 -2
View File
@@ -47,6 +47,11 @@ pub async fn fetch_forge_versions_from(
versions.sort();
versions.dedup();
tracing::debug!(
"Resolved {} Forge version(s) for Minecraft {} from promotions",
versions.len(),
game_version
);
Ok(versions)
}
@@ -70,6 +75,10 @@ pub async fn fetch_forge_game_versions_from(
game_versions.sort();
game_versions.dedup();
game_versions.reverse();
tracing::debug!(
"Resolved {} Forge game version(s) from promotions",
game_versions.len()
);
Ok(game_versions
.into_iter()
@@ -104,13 +113,20 @@ pub async fn download_forge_installer(
let mut last_err = None;
for slug in &slugs {
let url = format!("{}/{slug}/forge-{slug}-installer.jar", FORGE_MAVEN_BASE,);
tracing::debug!("Trying Forge installer slug '{}'", slug);
match download_file(client, &url, dest, |downloaded, total| {
crate::tui::progress::set_progress(downloaded, total);
})
.await
{
Ok(()) => return Ok(()),
Err(e) => last_err = Some(e),
Ok(()) => {
tracing::debug!("Downloaded Forge installer using slug '{}'", slug);
return Ok(());
}
Err(e) => {
tracing::debug!("Forge installer slug '{}' failed: {}", slug, e);
last_err = Some(e);
}
}
}
@@ -140,6 +156,12 @@ pub async fn run_forge_installer(
{
Ok(o) => o,
Err(e) => {
tracing::error!(
"Failed to spawn Forge installer {} with Java {}: {}",
installer_path.display(),
java_path,
e
);
return Err(NetError::Io(e));
}
};
@@ -151,9 +173,16 @@ pub async fn run_forge_installer(
} else {
stderr.lines().last().unwrap_or("unknown error").to_string()
};
tracing::error!(
"Forge installer {} failed with status {:?}: {}",
installer_path.display(),
output.status.code(),
detail
);
return Err(NetError::InstallerFailed(detail));
}
tracing::debug!("Forge installer completed successfully");
Ok(())
}
@@ -190,6 +219,11 @@ pub(crate) async fn install_forge_from_profile(
use std::io::Read;
set_action("Installing legacy Forge from profile...");
tracing::debug!(
"Installing legacy Forge from {} into {}",
installer_path.display(),
meta_dir.display()
);
let file = std::fs::File::open(installer_path)?;
let mut archive = zip::ZipArchive::new(file)
@@ -248,6 +282,11 @@ pub(crate) async fn install_forge_from_profile(
let mut buf = Vec::new();
entry.read_to_end(&mut buf)?;
std::fs::write(&universal_dest, &buf)?;
tracing::debug!(
"Extracted legacy Forge universal JAR to {} ({} bytes)",
universal_dest.display(),
buf.len()
);
}
// download libraries needed by this forge version. libs with a url field
@@ -267,6 +306,7 @@ pub(crate) async fn install_forge_from_profile(
let dest = libraries_dir.join(&maven_path);
if dest.exists() {
tracing::trace!("Legacy Forge library already cached: {}", name);
continue;
}
@@ -278,6 +318,7 @@ pub(crate) async fn install_forge_from_profile(
let download_url = format!("{base_url}/{maven_path}");
set_sub_action(name);
tracing::debug!("Downloading legacy Forge library {}", name);
download_file(client, &download_url, &dest, |_, _| {}).await?;
}
+57 -13
View File
@@ -42,14 +42,19 @@ impl Default for HttpClient {
impl HttpClient {
pub fn new() -> Self {
let user_agent = format!("rmcl/{} (Minecraft Launcher)", env!("CARGO_PKG_VERSION"));
let client = Client::builder()
.user_agent(format!(
"rmcl/{} (Minecraft Launcher)",
env!("CARGO_PKG_VERSION")
))
.user_agent(user_agent.clone())
.timeout(std::time::Duration::from_secs(30))
.build()
.unwrap_or_else(|_| Client::new());
.unwrap_or_else(|e| {
tracing::warn!(
"Failed to build configured HTTP client, falling back to reqwest default: {}",
e
);
Client::new()
});
tracing::trace!("Created HTTP client with user-agent '{}'", user_agent);
Self { inner: client }
}
@@ -58,13 +63,20 @@ impl HttpClient {
}
pub async fn get(&self, url: &str) -> Result<reqwest::Response, NetError> {
tracing::trace!("HTTP GET {}", url);
let response = self.inner.get(url).send().await?;
if !response.status().is_success() {
tracing::warn!(
"HTTP GET {} returned non-success status {}",
url,
response.status()
);
return Err(NetError::StatusError {
status: response.status().as_u16(),
url: url.to_string(),
});
}
tracing::trace!("HTTP GET {} succeeded with {}", url, response.status());
Ok(response)
}
@@ -90,7 +102,9 @@ impl HttpClient {
url: &str,
label: &str,
) -> Result<(T, Vec<u8>), NetError> {
tracing::debug!("Fetching {} JSON from {}", label, url);
let raw = self.get_bytes(url).await?;
tracing::trace!("Fetched {} byte(s) for {}", raw.len(), label);
let parsed: T = serde_json::from_slice(&raw)
.map_err(|e| NetError::Parse(format!("Failed to parse {label}: {e}")))?;
Ok((parsed, raw))
@@ -110,7 +124,8 @@ where
if attempt > 0 {
let delay = RETRY_BASE_DELAY_MS * 2u64.pow(attempt - 1);
tracing::warn!(
"retrying request (attempt {}/{}): {}",
"retrying request after {}ms (attempt {}/{}): {}",
delay,
attempt + 1,
MAX_RETRIES + 1,
url
@@ -121,10 +136,16 @@ where
match client.get(url).await {
Ok(resp) => match decode(resp).await {
Ok(value) => return Ok(value),
Err(e) if is_retryable(&e) => last_error = Some(e),
Err(e) if is_retryable(&e) => {
tracing::warn!("Retryable decode/request error for {}: {}", url, e);
last_error = Some(e);
}
Err(e) => return Err(e),
},
Err(e) if is_retryable(&e) => last_error = Some(e),
Err(e) if is_retryable(&e) => {
tracing::warn!("Retryable request error for {}: {}", url, e);
last_error = Some(e);
}
Err(e) => return Err(e),
}
}
@@ -144,12 +165,14 @@ pub async fn download_file(
progress_cb: impl Fn(u64, u64),
) -> Result<(), NetError> {
let mut last_error = None;
tracing::debug!("Downloading {} to {}", url, dest.display());
for attempt in 0..=MAX_RETRIES {
if attempt > 0 {
let delay = RETRY_BASE_DELAY_MS * 2u64.pow(attempt - 1);
tracing::warn!(
"retrying download (attempt {}/{}): {}",
"retrying download after {}ms (attempt {}/{}): {}",
delay,
attempt + 1,
MAX_RETRIES + 1,
url
@@ -158,8 +181,12 @@ pub async fn download_file(
}
match download_file_once(client, url, dest, &progress_cb).await {
Ok(()) => return Ok(()),
Ok(()) => {
tracing::debug!("Downloaded {} to {}", url, dest.display());
return Ok(());
}
Err(e) if is_retryable(&e) => {
tracing::warn!("Retryable download error for {}: {}", url, e);
last_error = Some(e);
}
Err(e) => return Err(e),
@@ -180,6 +207,7 @@ async fn download_file_once(
let response = client.get(url).await?;
let total = response.content_length().unwrap_or(0);
tracing::trace!("Download content length for {}: {}", url, total);
if let Some(parent) = dest.parent() {
tokio::fs::create_dir_all(parent).await?;
@@ -217,12 +245,28 @@ pub fn detect_java_path() -> String {
let java_name = if cfg!(windows) { "java.exe" } else { "java" };
let bin = std::path::Path::new(&java_home).join("bin").join(java_name);
if bin.exists() {
tracing::debug!("Detected Java from JAVA_HOME: {}", bin.display());
return bin.to_string_lossy().to_string();
}
tracing::warn!(
"JAVA_HOME is set to {}, but {} does not exist",
java_home,
bin.display()
);
}
match which::which("java") {
Ok(path) => {
tracing::debug!("Detected Java from PATH: {}", path.display());
path.to_string_lossy().to_string()
}
Err(e) => {
tracing::warn!(
"Could not find java on PATH, falling back to literal 'java': {}",
e
);
"java".to_string()
}
}
which::which("java")
.map(|p| p.to_string_lossy().to_string())
.unwrap_or_else(|_| "java".to_string())
}
// converts maven coordinates like "org.example:artifact:1.0" into a
+56 -5
View File
@@ -66,9 +66,16 @@ pub fn loader_from_dependencies(
];
for (key, loader) in &loaders {
if let Some(version) = deps.get(*key) {
tracing::trace!(
"Resolved Modrinth loader dependency {}={} as {}",
key,
version,
loader
);
return (Some(*loader), Some(version.clone()));
}
}
tracing::trace!("No Modrinth loader dependency found; treating pack as vanilla");
(None, None)
}
@@ -101,7 +108,14 @@ pub async fn fetch_project(
slug_or_id: &str,
) -> Result<ProjectInfo, crate::net::NetError> {
let url = format!("{}/project/{}", API_BASE, url_encode(slug_or_id));
client.get_json(&url).await
tracing::debug!("Fetching Modrinth project '{}'", slug_or_id);
let project: ProjectInfo = client.get_json(&url).await?;
tracing::debug!(
"Fetched Modrinth project '{}' ({})",
project.slug,
project.id
);
Ok(project)
}
pub async fn fetch_versions(
@@ -113,7 +127,14 @@ pub async fn fetch_versions(
API_BASE,
url_encode(slug_or_id)
);
client.get_json(&url).await
tracing::debug!("Fetching Modrinth versions for project '{}'", slug_or_id);
let versions: Vec<VersionInfo> = client.get_json(&url).await?;
tracing::debug!(
"Fetched {} Modrinth version(s) for project '{}'",
versions.len(),
slug_or_id
);
Ok(versions)
}
pub async fn fetch_version(
@@ -121,7 +142,15 @@ pub async fn fetch_version(
version_id: &str,
) -> Result<VersionInfo, crate::net::NetError> {
let url = format!("{}/version/{}", API_BASE, url_encode(version_id));
client.get_json(&url).await
tracing::debug!("Fetching Modrinth version '{}'", version_id);
let version: VersionInfo = client.get_json(&url).await?;
tracing::debug!(
"Fetched Modrinth version '{}' ({}) with {} file(s)",
version.name,
version.id,
version.files.len()
);
Ok(version)
}
// grabs the primary file from a version, falling back to the first file
@@ -135,22 +164,44 @@ pub async fn download_mrpack(
.files
.iter()
.find(|f| f.primary)
.or_else(|| version.files.first())
.or_else(|| {
tracing::warn!(
"Modrinth version '{}' has no primary file; using first file",
version.id
);
version.files.first()
})
.ok_or_else(|| crate::net::NetError::Parse("No files in version".to_string()))?;
let mrpack_path = dest.join(&file.filename);
tracing::info!(
"Downloading Modrinth pack file '{}' for version '{}' to {}",
file.filename,
version.id,
mrpack_path.display()
);
crate::net::download_file(client, &file.url, &mrpack_path, |_, _| {}).await?;
Ok(mrpack_path)
}
// .mrpack is just a zip with modrinth.index.json at the root
pub fn parse_mrpack(path: &std::path::Path) -> Result<MrpackIndex, String> {
tracing::debug!("Parsing .mrpack manifest from {}", path.display());
let file = std::fs::File::open(path).map_err(|e| format!("Cannot open .mrpack: {e}"))?;
let mut archive = zip::ZipArchive::new(file).map_err(|e| format!("Invalid ZIP: {e}"))?;
let entry = archive
.by_name("modrinth.index.json")
.map_err(|_| "Missing modrinth.index.json in .mrpack".to_string())?;
serde_json::from_reader(entry).map_err(|e| format!("Invalid manifest JSON: {e}"))
let index: MrpackIndex =
serde_json::from_reader(entry).map_err(|e| format!("Invalid manifest JSON: {e}"))?;
tracing::debug!(
"Parsed .mrpack '{}' version_id={} files={} deps={}",
index.name,
index.version_id,
index.files.len(),
index.dependencies.len()
);
Ok(index)
}
#[cfg(test)]
+68 -5
View File
@@ -120,7 +120,15 @@ pub async fn fetch_version_manifest_from(
client: &HttpClient,
url: &str,
) -> Result<VersionManifest, NetError> {
client.get_json(url).await
tracing::debug!("Fetching Mojang version manifest from {}", url);
let manifest: VersionManifest = client.get_json(url).await?;
tracing::debug!(
"Fetched Mojang manifest with {} version(s); latest release={} snapshot={}",
manifest.versions.len(),
manifest.latest.release,
manifest.latest.snapshot
);
Ok(manifest)
}
// fetches and parses a version's metadata. also returns the raw response
@@ -131,6 +139,11 @@ pub async fn fetch_version_meta_with_raw(
client: &HttpClient,
entry: &VersionEntry,
) -> Result<(VersionMeta, Vec<u8>), NetError> {
tracing::debug!(
"Fetching Mojang version meta '{}' from {}",
entry.id,
entry.url
);
client.get_json_with_raw(&entry.url, "version meta").await
}
@@ -146,10 +159,16 @@ pub async fn download_client_jar(
if jar_path.exists() {
tracing::info!("Client JAR already cached: {}", meta.id);
tracing::trace!("Cached client JAR path: {}", jar_path.display());
return Ok(());
}
set_action(format!("Downloading Minecraft {}...", meta.id));
tracing::info!(
"Downloading Minecraft client JAR {} to {}",
meta.id,
jar_path.display()
);
let result = download_file(
client,
@@ -171,6 +190,11 @@ pub async fn download_libraries(
meta_dir: &Path,
) -> Result<(), NetError> {
set_action("Downloading libraries...");
tracing::debug!(
"Resolving {} libraries for Minecraft {}",
meta.libraries.len(),
meta.id
);
let features = crate::launch_profile::rules::FeatureSet::default();
let host_os_version = crate::launch_profile::system::mojang_os_version();
@@ -186,17 +210,25 @@ pub async fn download_libraries(
if let Some(rules) = &library.rules
&& !crate::launch_profile::rules::evaluate(rules, &rule_ctx)
{
tracing::trace!("Skipping library {} due to platform rules", library.name);
continue;
}
let artifact = match &library.downloads.artifact {
Some(artifact) => artifact,
None => continue,
None => {
tracing::trace!(
"Skipping library {} without artifact download",
library.name
);
continue;
}
};
let destination = meta_dir.join("libraries").join(&artifact.path);
if destination.exists() {
tracing::trace!("Library already cached: {}", artifact.path);
continue;
}
@@ -209,6 +241,7 @@ pub async fn download_libraries(
return Ok(());
}
tracing::debug!("Downloading {} missing libraries", downloads.len());
let result = run_parallel_downloads(client, downloads, false).await;
clear();
result
@@ -231,6 +264,11 @@ pub async fn download_assets_from(
assets_base: &str,
) -> Result<(), NetError> {
set_action("Downloading assets...");
tracing::debug!(
"Fetching asset index {} from {}",
meta.asset_index.id,
meta.asset_index.url
);
let asset_index: AssetIndexContent = match client.get_json(&meta.asset_index.url).await {
Ok(index) => index,
@@ -256,9 +294,15 @@ pub async fn download_assets_from(
}
}
match tokio::fs::write(&index_path, json).await {
Ok(_) => {}
Ok(_) => {
tracing::debug!("Saved asset index to {}", index_path.display());
}
Err(e) => {
tracing::error!("Failed to write asset index: {}", e);
tracing::error!(
"Failed to write asset index {}: {}",
index_path.display(),
e
);
}
}
}
@@ -289,6 +333,7 @@ pub async fn download_assets_from(
.join(&object.hash);
if destination.exists() {
tracing::trace!("Asset already cached: {}", object.hash);
continue;
}
@@ -301,6 +346,11 @@ pub async fn download_assets_from(
return Ok(());
}
tracing::debug!(
"Downloading {} missing asset(s) from index {}",
downloads.len(),
meta.asset_index.id
);
let result = run_parallel_downloads(client, downloads, true).await;
clear();
result
@@ -315,6 +365,11 @@ async fn run_parallel_downloads(
report_count_progress: bool,
) -> Result<(), NetError> {
let total_downloads = downloads.len() as u64;
tracing::debug!(
"Starting {} parallel download job(s), max_concurrent={}",
total_downloads,
MAX_CONCURRENT_DOWNLOADS
);
let completed = Arc::new(AtomicU64::new(0));
let mut queue = downloads.into_iter();
let mut set = JoinSet::new();
@@ -376,8 +431,16 @@ fn spawn_download_task(
let task_client = client.clone();
set.spawn(async move {
tracing::trace!(
"Starting parallel download '{}' to {}",
label,
destination.display()
);
let result = download_file(&task_client, &url, &destination, |_current, _total| {}).await;
result.map(|()| label)
result.map(|()| {
tracing::trace!("Finished parallel download '{}'", label);
label
})
});
}
+27
View File
@@ -64,6 +64,12 @@ pub async fn fetch_neoforge_versions_from(
.filter(|v| v.starts_with(&prefix) && !v.contains("-beta") && !v.contains("-alpha"))
.collect();
tracing::debug!(
"Resolved {} NeoForge version(s) for Minecraft {} with prefix {}",
versions.len(),
game_version,
prefix
);
Ok(versions)
}
@@ -99,6 +105,7 @@ pub async fn fetch_neoforge_game_versions_from(
}
}
game_versions.reverse();
tracing::debug!("Resolved {} NeoForge game version(s)", game_versions.len());
Ok(game_versions
.into_iter()
@@ -120,6 +127,11 @@ pub async fn download_neoforge_installer(
);
set_action(format!("Downloading NeoForge {}...", neoforge_version));
tracing::info!(
"Downloading NeoForge installer {} to {}",
neoforge_version,
dest.display()
);
download_file(client, &url, dest, |downloaded, total| {
crate::tui::progress::set_progress(downloaded, total);
@@ -146,17 +158,32 @@ pub async fn run_neoforge_installer(
{
Ok(o) => o,
Err(e) => {
tracing::error!(
"Failed to spawn NeoForge installer {} with Java {}: {}",
installer_path.display(),
java_path,
e
);
return Err(NetError::Io(e));
}
};
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
let detail = stderr.lines().last().unwrap_or("").trim();
tracing::error!(
"NeoForge installer {} failed with status {:?}: {}",
installer_path.display(),
output.status.code(),
detail
);
return Err(NetError::InstallerFailed(format!(
"NeoForge installer exited with {:?}",
output.status.code()
)));
}
tracing::debug!("NeoForge installer completed successfully");
Ok(())
}
+27 -1
View File
@@ -52,7 +52,9 @@ pub async fn fetch_quilt_game_versions_from(
meta_base: &str,
) -> Result<Vec<GameVersion>, NetError> {
let url = format!("{}/versions/game", meta_base);
tracing::debug!("Fetching Quilt game versions from {}", url);
let versions: Vec<QuiltGameVersion> = client.get_json(&url).await?;
tracing::debug!("Fetched {} Quilt game version(s)", versions.len());
Ok(versions
.into_iter()
@@ -76,7 +78,14 @@ pub async fn fetch_quilt_versions_from(
game_version: &str,
) -> Result<Vec<QuiltLoaderVersion>, NetError> {
let url = format!("{}/versions/loader/{}", meta_base, game_version);
client.get_json(&url).await
tracing::debug!("Fetching Quilt loader versions for {}", game_version);
let versions: Vec<QuiltLoaderVersion> = client.get_json(&url).await?;
tracing::debug!(
"Fetched {} Quilt loader version(s) for {}",
versions.len(),
game_version
);
Ok(versions)
}
pub async fn fetch_quilt_profile(
@@ -97,6 +106,11 @@ pub async fn fetch_quilt_profile_from(
"{}/versions/loader/{}/{}/profile/json",
meta_base, game_version, loader_version
);
tracing::debug!(
"Fetching Quilt profile for Minecraft {} loader {}",
game_version,
loader_version
);
client.get_json(&url).await
}
@@ -122,6 +136,11 @@ pub async fn fetch_quilt_profile_with_raw_from(
"{}/versions/loader/{}/{}/profile/json",
meta_base, game_version, loader_version
);
tracing::debug!(
"Fetching raw Quilt profile for Minecraft {} loader {}",
game_version,
loader_version
);
client.get_json_with_raw(&url, "Quilt profile").await
}
@@ -131,6 +150,11 @@ pub async fn download_quilt_libraries(
meta_dir: &Path,
) -> Result<(), NetError> {
let libraries_dir = meta_dir.join("libraries");
tracing::debug!(
"Resolving {} Quilt libraries into {}",
profile.libraries.len(),
libraries_dir.display()
);
for lib in &profile.libraries {
let maven_path = match crate::net::maven_coord_to_path(&lib.name) {
@@ -155,10 +179,12 @@ pub async fn download_quilt_libraries(
set_sub_action(&lib.name);
tracing::info!("Downloading Quilt library: {}", lib.name);
tracing::trace!("Quilt library destination: {}", dest.display());
download_file(client, &download_url, &dest, |_, _| {}).await?;
}
tracing::debug!("Quilt library resolution complete for {}", profile.id);
Ok(())
}