fixed duplicate error messages on installer failure and added new error type
This commit is contained in:
1 parent
1fd1b4e09d
commit
c5da2c7c99
12 files changed
+109
-81
No files matched your search
+33
-27
@@ -7,7 +7,7 @@ use std::path::Path;
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::instance::loader::GameVersion;
|
||||
use crate::instance::loader::{GameVersion, InstallError, InstallerError};
|
||||
use crate::net::{HttpClient, NetError, download_file};
|
||||
use crate::tui::progress::{set_action, set_sub_action};
|
||||
|
||||
@@ -141,7 +141,7 @@ pub async fn run_forge_installer(
|
||||
installer_path: &Path,
|
||||
instance_dir: &Path,
|
||||
java_path: &str,
|
||||
) -> Result<(), NetError> {
|
||||
) -> Result<(), InstallerError> {
|
||||
use tokio::process::Command;
|
||||
|
||||
set_action("Running Forge installer...");
|
||||
@@ -156,13 +156,13 @@ pub async fn run_forge_installer(
|
||||
{
|
||||
Ok(o) => o,
|
||||
Err(e) => {
|
||||
tracing::error!(
|
||||
tracing::debug!(
|
||||
"Failed to spawn Forge installer {} with Java {}: {}",
|
||||
installer_path.display(),
|
||||
java_path,
|
||||
e
|
||||
);
|
||||
return Err(NetError::Io(e));
|
||||
return Err(InstallerError::Io(e));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -173,13 +173,13 @@ pub async fn run_forge_installer(
|
||||
} else {
|
||||
stderr.lines().last().unwrap_or("unknown error").to_string()
|
||||
};
|
||||
tracing::error!(
|
||||
tracing::debug!(
|
||||
"Forge installer {} failed with status {:?}: {}",
|
||||
installer_path.display(),
|
||||
output.status.code(),
|
||||
detail
|
||||
);
|
||||
return Err(NetError::InstallerFailed(detail));
|
||||
return Err(InstallerError::ProcessFailed(detail));
|
||||
}
|
||||
|
||||
tracing::debug!("Forge installer completed successfully");
|
||||
@@ -215,7 +215,7 @@ pub(crate) async fn install_forge_from_profile(
|
||||
installer_path: &Path,
|
||||
meta_dir: &Path,
|
||||
profile_filename: &str,
|
||||
) -> Result<(), NetError> {
|
||||
) -> Result<(), InstallError> {
|
||||
use std::io::Read;
|
||||
|
||||
set_action("Installing legacy Forge from profile...");
|
||||
@@ -225,63 +225,68 @@ pub(crate) async fn install_forge_from_profile(
|
||||
meta_dir.display()
|
||||
);
|
||||
|
||||
let file = std::fs::File::open(installer_path)?;
|
||||
let file = std::fs::File::open(installer_path)
|
||||
.map_err(|e| InstallError::Installer(InstallerError::Io(e)))?;
|
||||
let mut archive = zip::ZipArchive::new(file)
|
||||
.map_err(|e| NetError::Parse(format!("Failed to open installer as ZIP: {e}")))?;
|
||||
.map_err(|e| InstallError::Installer(InstallerError::Profile(format!("Failed to open installer as ZIP: {e}"))))?;
|
||||
|
||||
let profile_data: serde_json::Value = {
|
||||
let entry = archive.by_name("install_profile.json").map_err(|e| {
|
||||
NetError::Parse(format!("install_profile.json not found in installer: {e}"))
|
||||
InstallError::Installer(InstallerError::Profile(format!("install_profile.json not found in installer: {e}")))
|
||||
})?;
|
||||
serde_json::from_reader(entry)
|
||||
.map_err(|e| NetError::Parse(format!("Failed to parse install_profile.json: {e}")))?
|
||||
.map_err(|e| InstallError::Installer(InstallerError::Profile(format!("Failed to parse install_profile.json: {e}"))))?
|
||||
};
|
||||
|
||||
let version_info = profile_data
|
||||
.get("versionInfo")
|
||||
.ok_or_else(|| NetError::Parse("install_profile.json missing versionInfo".into()))?;
|
||||
.ok_or_else(|| InstallError::Installer(InstallerError::Profile("install_profile.json missing versionInfo".into())))?;
|
||||
let install_info = profile_data
|
||||
.get("install")
|
||||
.ok_or_else(|| NetError::Parse("install_profile.json missing install section".into()))?;
|
||||
.ok_or_else(|| InstallError::Installer(InstallerError::Profile("install_profile.json missing install section".into())))?;
|
||||
|
||||
let libraries = version_info
|
||||
.get("libraries")
|
||||
.and_then(|v| v.as_array())
|
||||
.ok_or_else(|| NetError::Parse("missing versionInfo.libraries".into()))?;
|
||||
.ok_or_else(|| InstallError::Installer(InstallerError::Profile("missing versionInfo.libraries".into())))?;
|
||||
|
||||
let file_path = install_info
|
||||
.get("filePath")
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or_else(|| NetError::Parse("missing install.filePath".into()))?;
|
||||
.ok_or_else(|| InstallError::Installer(InstallerError::Profile("missing install.filePath".into())))?;
|
||||
|
||||
let install_path_coord = install_info
|
||||
.get("path")
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or_else(|| NetError::Parse("missing install.path".into()))?;
|
||||
.ok_or_else(|| InstallError::Installer(InstallerError::Profile("missing install.path".into())))?;
|
||||
|
||||
// extract the universal jar to the correct maven location
|
||||
let universal_maven_path =
|
||||
crate::net::maven_coord_to_path(install_path_coord).ok_or_else(|| {
|
||||
NetError::Parse(format!(
|
||||
InstallError::Installer(InstallerError::Profile(format!(
|
||||
"Invalid maven coord in install.path: {install_path_coord}"
|
||||
))
|
||||
)))
|
||||
})?;
|
||||
|
||||
set_sub_action("Extracting universal JAR...");
|
||||
let universal_dest = meta_dir.join("libraries").join(&universal_maven_path);
|
||||
if let Some(parent) = universal_dest.parent() {
|
||||
std::fs::create_dir_all(parent)?;
|
||||
std::fs::create_dir_all(parent)
|
||||
.map_err(|e| InstallError::Installer(InstallerError::Io(e)))?;
|
||||
}
|
||||
|
||||
{
|
||||
let mut entry = archive.by_name(file_path).map_err(|e| {
|
||||
NetError::Parse(format!(
|
||||
InstallError::Installer(InstallerError::Profile(format!(
|
||||
"Universal JAR '{file_path}' not found in installer: {e}"
|
||||
))
|
||||
)))
|
||||
})?;
|
||||
let mut buf = Vec::new();
|
||||
entry.read_to_end(&mut buf)?;
|
||||
std::fs::write(&universal_dest, &buf)?;
|
||||
entry
|
||||
.read_to_end(&mut buf)
|
||||
.map_err(|e| InstallError::Installer(InstallerError::Io(e)))?;
|
||||
std::fs::write(&universal_dest, &buf)
|
||||
.map_err(|e| InstallError::Installer(InstallerError::Io(e)))?;
|
||||
tracing::debug!(
|
||||
"Extracted legacy Forge universal JAR to {} ({} bytes)",
|
||||
universal_dest.display(),
|
||||
@@ -295,12 +300,12 @@ pub(crate) async fn install_forge_from_profile(
|
||||
// in mojang's modern version metadata, so we fetch those too.
|
||||
let libraries_dir = meta_dir.join("libraries");
|
||||
for lib in libraries {
|
||||
let name = lib.get("name").and_then(|v| v.as_str()).unwrap_or_default();
|
||||
let name = lib.get("name").and_then(|v| v.as_str()).unwrap_or_default();
|
||||
|
||||
let maven_path = match crate::net::maven_coord_to_path(name) {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
return Err(NetError::Parse(format!("Invalid Maven coordinate: {name}")));
|
||||
return Err(InstallError::Installer(InstallerError::Profile(format!("Invalid Maven coordinate: {name}"))));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -337,8 +342,9 @@ pub(crate) async fn install_forge_from_profile(
|
||||
// the source is a serde_json::Value (which doesn't preserve order),
|
||||
// but no field is silently dropped.
|
||||
let serialized = serde_json::to_vec(version_info)
|
||||
.map_err(|e| NetError::Parse(format!("Failed to serialize Forge profile: {e}")))?;
|
||||
crate::instance::loader::save_profile_bytes(meta_dir, profile_filename, &serialized)?;
|
||||
.map_err(|e| InstallError::Installer(InstallerError::Profile(format!("Failed to serialize Forge profile: {e}"))))?;
|
||||
crate::instance::loader::save_profile_bytes(meta_dir, profile_filename, &serialized)
|
||||
.map_err(|e| InstallError::Installer(InstallerError::Io(e)))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ pub enum NetError {
|
||||
Parse(String),
|
||||
#[error("Server returned error status {status}: {url}")]
|
||||
StatusError { status: u16, url: String },
|
||||
#[error("Installer process failed: {0}")]
|
||||
InstallerFailed(String),
|
||||
#[error("Task failed: {0}")]
|
||||
TaskFailed(String),
|
||||
}
|
||||
|
||||
+5
-5
@@ -289,7 +289,7 @@ pub async fn download_assets_from(
|
||||
match tokio::fs::create_dir_all(parent).await {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
tracing::error!("Failed to create asset index dir: {}", e);
|
||||
tracing::debug!("Failed to create asset index dir: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -298,7 +298,7 @@ pub async fn download_assets_from(
|
||||
tracing::debug!("Saved asset index to {}", index_path.display());
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!(
|
||||
tracing::debug!(
|
||||
"Failed to write asset index {}: {}",
|
||||
index_path.display(),
|
||||
e
|
||||
@@ -307,7 +307,7 @@ pub async fn download_assets_from(
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Failed to serialize asset index: {}", e);
|
||||
tracing::debug!("Failed to serialize asset index: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -394,13 +394,13 @@ async fn run_parallel_downloads(
|
||||
set_sub_action(label);
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
tracing::error!("Download failed: {}", e);
|
||||
tracing::debug!("Download failed: {}", e);
|
||||
if first_error.is_none() {
|
||||
first_error = Some(e);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Task panicked: {}", e);
|
||||
tracing::debug!("Task panicked: {}", e);
|
||||
if first_error.is_none() {
|
||||
first_error = Some(NetError::TaskFailed(format!("Join error: {}", e)));
|
||||
}
|
||||
|
||||
+6
-5
@@ -8,6 +8,7 @@ use std::path::Path;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::instance::loader::GameVersion;
|
||||
use crate::instance::loader::InstallerError;
|
||||
use crate::net::{HttpClient, NetError, download_file};
|
||||
use crate::tui::progress::set_action;
|
||||
|
||||
@@ -171,7 +172,7 @@ pub async fn run_neoforge_installer(
|
||||
installer_path: &Path,
|
||||
instance_dir: &Path,
|
||||
java_path: &str,
|
||||
) -> Result<(), NetError> {
|
||||
) -> Result<(), InstallerError> {
|
||||
use tokio::process::Command;
|
||||
|
||||
set_action("Running NeoForge installer...");
|
||||
@@ -186,26 +187,26 @@ pub async fn run_neoforge_installer(
|
||||
{
|
||||
Ok(o) => o,
|
||||
Err(e) => {
|
||||
tracing::error!(
|
||||
tracing::debug!(
|
||||
"Failed to spawn NeoForge installer {} with Java {}: {}",
|
||||
installer_path.display(),
|
||||
java_path,
|
||||
e
|
||||
);
|
||||
return Err(NetError::Io(e));
|
||||
return Err(InstallerError::Io(e));
|
||||
}
|
||||
};
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
let detail = stderr.lines().last().unwrap_or("").trim();
|
||||
tracing::error!(
|
||||
tracing::debug!(
|
||||
"NeoForge installer {} failed with status {:?}: {}",
|
||||
installer_path.display(),
|
||||
output.status.code(),
|
||||
detail
|
||||
);
|
||||
return Err(NetError::InstallerFailed(format!(
|
||||
return Err(InstallerError::ProcessFailed(format!(
|
||||
"NeoForge installer exited with {:?}",
|
||||
output.status.code()
|
||||
)));
|
||||
|
||||
Reference in new issue
Block a user