fixed duplicate logs
This commit is contained in:
1 parent
09f403aa07
commit
0d9cd9c6b8
6 files changed
+79
-56
No files matched your search
@@ -70,7 +70,6 @@ impl ModLoaderInstaller for ForgeInstaller {
|
|||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
let _ = tokio::fs::remove_file(&installer_jar).await;
|
let _ = tokio::fs::remove_file(&installer_jar).await;
|
||||||
tracing::error!("Legacy Forge installation failed: {}", e);
|
|
||||||
return Err(e);
|
return Err(e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -85,7 +84,6 @@ impl ModLoaderInstaller for ForgeInstaller {
|
|||||||
forge_api::run_forge_installer(&installer_jar, instance_dir, &java_path).await
|
forge_api::run_forge_installer(&installer_jar, instance_dir, &java_path).await
|
||||||
{
|
{
|
||||||
let _ = tokio::fs::remove_file(&installer_jar).await;
|
let _ = tokio::fs::remove_file(&installer_jar).await;
|
||||||
tracing::error!("Modern Forge installer failed: {}", e);
|
|
||||||
return Err(e);
|
return Err(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ impl ModLoaderInstaller for NeoForgeInstaller {
|
|||||||
neoforge_api::run_neoforge_installer(&installer_jar, instance_dir, &java_path).await
|
neoforge_api::run_neoforge_installer(&installer_jar, instance_dir, &java_path).await
|
||||||
{
|
{
|
||||||
let _ = tokio::fs::remove_file(&installer_jar).await;
|
let _ = tokio::fs::remove_file(&installer_jar).await;
|
||||||
tracing::error!("NeoForge installer failed: {}", e);
|
|
||||||
return Err(e);
|
return Err(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+48
-11
@@ -92,8 +92,11 @@ impl InstanceManager {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
// clean up on failure so there's no half-baked instance left around
|
// clean up on failure so there's no half-baked instance left around
|
||||||
if let Err(e) = &result {
|
if result.is_err() {
|
||||||
tracing::error!("Instance '{}' creation failed: {}", name, e);
|
tracing::debug!(
|
||||||
|
"Cleaning up incomplete instance '{}' after creation failed",
|
||||||
|
name
|
||||||
|
);
|
||||||
if let Err(cleanup_error) = std::fs::remove_dir_all(&instance_dir) {
|
if let Err(cleanup_error) = std::fs::remove_dir_all(&instance_dir) {
|
||||||
tracing::warn!(
|
tracing::warn!(
|
||||||
"Failed to clean up incomplete instance directory {}: {}",
|
"Failed to clean up incomplete instance directory {}: {}",
|
||||||
@@ -171,14 +174,10 @@ impl InstanceManager {
|
|||||||
v
|
v
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
tracing::warn!(
|
return Err(InstanceError::InvalidName(format!(
|
||||||
"Minecraft version '{}' not found in manifest with {} entries",
|
"Minecraft version '{}' not found in manifest with {} entries",
|
||||||
game_version,
|
game_version,
|
||||||
manifest.versions.len()
|
manifest.versions.len()
|
||||||
);
|
|
||||||
return Err(InstanceError::InvalidName(format!(
|
|
||||||
"Minecraft version '{}' not found in manifest",
|
|
||||||
game_version
|
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -282,7 +281,14 @@ impl InstanceManager {
|
|||||||
return Err(InstanceError::NotFound(name.to_string()));
|
return Err(InstanceError::NotFound(name.to_string()));
|
||||||
}
|
}
|
||||||
tracing::info!("Deleting instance '{}' at {}", name, instance_dir.display());
|
tracing::info!("Deleting instance '{}' at {}", name, instance_dir.display());
|
||||||
std::fs::remove_dir_all(&instance_dir)?;
|
if let Err(e) = std::fs::remove_dir_all(&instance_dir) {
|
||||||
|
tracing::error!(
|
||||||
|
"Failed to delete instance directory {}: {}",
|
||||||
|
instance_dir.display(),
|
||||||
|
e
|
||||||
|
);
|
||||||
|
return Err(e.into());
|
||||||
|
}
|
||||||
if let Err(e) = crate::instance::desktop::remove(name) {
|
if let Err(e) = crate::instance::desktop::remove(name) {
|
||||||
tracing::warn!("Failed to remove desktop shortcut for '{}': {}", name, e);
|
tracing::warn!("Failed to remove desktop shortcut for '{}': {}", name, e);
|
||||||
}
|
}
|
||||||
@@ -292,6 +298,7 @@ impl InstanceManager {
|
|||||||
pub fn rename(&self, old_name: &str, new_name: &str) -> Result<(), InstanceError> {
|
pub fn rename(&self, old_name: &str, new_name: &str) -> Result<(), InstanceError> {
|
||||||
let new_name = new_name.trim();
|
let new_name = new_name.trim();
|
||||||
if new_name.is_empty() {
|
if new_name.is_empty() {
|
||||||
|
tracing::warn!("Cannot rename instance '{}': new name is empty", old_name);
|
||||||
return Err(InstanceError::InvalidName(
|
return Err(InstanceError::InvalidName(
|
||||||
"Name cannot be empty".to_string(),
|
"Name cannot be empty".to_string(),
|
||||||
));
|
));
|
||||||
@@ -320,7 +327,15 @@ impl InstanceManager {
|
|||||||
return Err(InstanceError::AlreadyExists(new_name.to_string()));
|
return Err(InstanceError::AlreadyExists(new_name.to_string()));
|
||||||
}
|
}
|
||||||
tracing::info!("Renaming instance '{}' to '{}'", old_name, new_name);
|
tracing::info!("Renaming instance '{}' to '{}'", old_name, new_name);
|
||||||
std::fs::rename(&old_dir, &new_dir)?;
|
if let Err(e) = std::fs::rename(&old_dir, &new_dir) {
|
||||||
|
tracing::error!(
|
||||||
|
"Failed to rename instance directory {} to {}: {}",
|
||||||
|
old_dir.display(),
|
||||||
|
new_dir.display(),
|
||||||
|
e
|
||||||
|
);
|
||||||
|
return Err(e.into());
|
||||||
|
}
|
||||||
|
|
||||||
let config_path = new_dir.join("instance.json");
|
let config_path = new_dir.join("instance.json");
|
||||||
if let Ok(data) = std::fs::read_to_string(&config_path)
|
if let Ok(data) = std::fs::read_to_string(&config_path)
|
||||||
@@ -402,8 +417,30 @@ impl InstanceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tracing::debug!("Loading instance '{}' from {}", name, config_path.display());
|
tracing::debug!("Loading instance '{}' from {}", name, config_path.display());
|
||||||
let contents = std::fs::read_to_string(&config_path)?;
|
let contents = match std::fs::read_to_string(&config_path) {
|
||||||
Ok(serde_json::from_str::<InstanceConfig>(&contents)?)
|
Ok(contents) => contents,
|
||||||
|
Err(e) => {
|
||||||
|
tracing::error!(
|
||||||
|
"Failed to read instance '{}' config {}: {}",
|
||||||
|
name,
|
||||||
|
config_path.display(),
|
||||||
|
e
|
||||||
|
);
|
||||||
|
return Err(e.into());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
match serde_json::from_str::<InstanceConfig>(&contents) {
|
||||||
|
Ok(config) => Ok(config),
|
||||||
|
Err(e) => {
|
||||||
|
tracing::error!(
|
||||||
|
"Failed to parse instance '{}' config {}: {}",
|
||||||
|
name,
|
||||||
|
config_path.display(),
|
||||||
|
e
|
||||||
|
);
|
||||||
|
Err(e.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save(&self, instance: &InstanceConfig) -> Result<(), InstanceError> {
|
pub fn save(&self, instance: &InstanceConfig) -> Result<(), InstanceError> {
|
||||||
|
|||||||
+29
-35
@@ -66,7 +66,7 @@ impl HttpClient {
|
|||||||
tracing::trace!("HTTP GET {}", url);
|
tracing::trace!("HTTP GET {}", url);
|
||||||
let response = self.inner.get(url).send().await?;
|
let response = self.inner.get(url).send().await?;
|
||||||
if !response.status().is_success() {
|
if !response.status().is_success() {
|
||||||
tracing::warn!(
|
tracing::debug!(
|
||||||
"HTTP GET {} returned non-success status {}",
|
"HTTP GET {} returned non-success status {}",
|
||||||
url,
|
url,
|
||||||
response.status()
|
response.status()
|
||||||
@@ -119,42 +119,47 @@ where
|
|||||||
F: Fn(reqwest::Response) -> Fut,
|
F: Fn(reqwest::Response) -> Fut,
|
||||||
Fut: std::future::Future<Output = Result<T, NetError>>,
|
Fut: std::future::Future<Output = Result<T, NetError>>,
|
||||||
{
|
{
|
||||||
let mut last_error = None;
|
|
||||||
for attempt in 0..=MAX_RETRIES {
|
for attempt in 0..=MAX_RETRIES {
|
||||||
if attempt > 0 {
|
|
||||||
let delay = RETRY_BASE_DELAY_MS * 2u64.pow(attempt - 1);
|
|
||||||
tracing::warn!(
|
|
||||||
"retrying request after {}ms (attempt {}/{}): {}",
|
|
||||||
delay,
|
|
||||||
attempt + 1,
|
|
||||||
MAX_RETRIES + 1,
|
|
||||||
url
|
|
||||||
);
|
|
||||||
tokio::time::sleep(std::time::Duration::from_millis(delay)).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
match client.get(url).await {
|
match client.get(url).await {
|
||||||
Ok(resp) => match decode(resp).await {
|
Ok(resp) => match decode(resp).await {
|
||||||
Ok(value) => return Ok(value),
|
Ok(value) => return Ok(value),
|
||||||
Err(e) if is_retryable(&e) => {
|
Err(e) if is_retryable(&e) => {
|
||||||
tracing::warn!("Retryable decode/request error for {}: {}", url, e);
|
if attempt == MAX_RETRIES {
|
||||||
last_error = Some(e);
|
return Err(e);
|
||||||
|
}
|
||||||
|
sleep_before_retry("request", url, attempt, &e).await;
|
||||||
}
|
}
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
},
|
},
|
||||||
Err(e) if is_retryable(&e) => {
|
Err(e) if is_retryable(&e) => {
|
||||||
tracing::warn!("Retryable request error for {}: {}", url, e);
|
if attempt == MAX_RETRIES {
|
||||||
last_error = Some(e);
|
return Err(e);
|
||||||
|
}
|
||||||
|
sleep_before_retry("request", url, attempt, &e).await;
|
||||||
}
|
}
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(last_error.unwrap())
|
unreachable!("retry loop returns on success or final error")
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAX_RETRIES: u32 = 3;
|
const MAX_RETRIES: u32 = 3;
|
||||||
const RETRY_BASE_DELAY_MS: u64 = 500;
|
const RETRY_BASE_DELAY_MS: u64 = 500;
|
||||||
|
|
||||||
|
async fn sleep_before_retry(kind: &str, url: &str, attempt: u32, err: &NetError) {
|
||||||
|
let delay = RETRY_BASE_DELAY_MS * 2u64.pow(attempt);
|
||||||
|
tracing::warn!(
|
||||||
|
"{} failed, retrying after {}ms (attempt {}/{}): {}: {}",
|
||||||
|
kind,
|
||||||
|
delay,
|
||||||
|
attempt + 2,
|
||||||
|
MAX_RETRIES + 1,
|
||||||
|
url,
|
||||||
|
err
|
||||||
|
);
|
||||||
|
tokio::time::sleep(std::time::Duration::from_millis(delay)).await;
|
||||||
|
}
|
||||||
|
|
||||||
// streams a file to disk in chunks, calling progress_cb(downloaded, total) along the way.
|
// streams a file to disk in chunks, calling progress_cb(downloaded, total) along the way.
|
||||||
// total will be 0 if the server doesn't send content-length, so callers
|
// total will be 0 if the server doesn't send content-length, so callers
|
||||||
// should handle that gracefully. retries transient failures with exponential backoff.
|
// should handle that gracefully. retries transient failures with exponential backoff.
|
||||||
@@ -164,36 +169,25 @@ pub async fn download_file(
|
|||||||
dest: &Path,
|
dest: &Path,
|
||||||
progress_cb: impl Fn(u64, u64),
|
progress_cb: impl Fn(u64, u64),
|
||||||
) -> Result<(), NetError> {
|
) -> Result<(), NetError> {
|
||||||
let mut last_error = None;
|
|
||||||
tracing::debug!("Downloading {} to {}", url, dest.display());
|
tracing::debug!("Downloading {} to {}", url, dest.display());
|
||||||
|
|
||||||
for attempt in 0..=MAX_RETRIES {
|
for attempt in 0..=MAX_RETRIES {
|
||||||
if attempt > 0 {
|
|
||||||
let delay = RETRY_BASE_DELAY_MS * 2u64.pow(attempt - 1);
|
|
||||||
tracing::warn!(
|
|
||||||
"retrying download after {}ms (attempt {}/{}): {}",
|
|
||||||
delay,
|
|
||||||
attempt + 1,
|
|
||||||
MAX_RETRIES + 1,
|
|
||||||
url
|
|
||||||
);
|
|
||||||
tokio::time::sleep(std::time::Duration::from_millis(delay)).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
match download_file_once(client, url, dest, &progress_cb).await {
|
match download_file_once(client, url, dest, &progress_cb).await {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
tracing::debug!("Downloaded {} to {}", url, dest.display());
|
tracing::debug!("Downloaded {} to {}", url, dest.display());
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
Err(e) if is_retryable(&e) => {
|
Err(e) if is_retryable(&e) => {
|
||||||
tracing::warn!("Retryable download error for {}: {}", url, e);
|
if attempt == MAX_RETRIES {
|
||||||
last_error = Some(e);
|
return Err(e);
|
||||||
|
}
|
||||||
|
sleep_before_retry("download", url, attempt, &e).await;
|
||||||
}
|
}
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(last_error.unwrap())
|
unreachable!("retry loop returns on success or final error")
|
||||||
}
|
}
|
||||||
|
|
||||||
// single attempt at downloading a file to disk
|
// single attempt at downloading a file to disk
|
||||||
|
|||||||
@@ -254,7 +254,6 @@ impl App {
|
|||||||
let instance = match self.instance_manager.load_one(&instance.name) {
|
let instance = match self.instance_manager.load_one(&instance.name) {
|
||||||
Ok(config) => config,
|
Ok(config) => config,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!("Failed to load instance '{}': {}", instance.name, e);
|
|
||||||
error_buffer::push_error(error_buffer::ErrorEvent {
|
error_buffer::push_error(error_buffer::ErrorEvent {
|
||||||
id: 0,
|
id: 0,
|
||||||
level: tracing::Level::ERROR,
|
level: tracing::Level::ERROR,
|
||||||
|
|||||||
+2
-6
@@ -76,9 +76,7 @@ impl App {
|
|||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
self.instances_state.remove_instance(&name);
|
self.instances_state.remove_instance(&name);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(_) => {}
|
||||||
tracing::error!("Failed to delete instance '{}': {}", name, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
confirm_popup::clear_pending();
|
confirm_popup::clear_pending();
|
||||||
@@ -203,9 +201,7 @@ impl App {
|
|||||||
inst.name = new_name.trim().to_owned();
|
inst.name = new_name.trim().to_owned();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(_) => {}
|
||||||
tracing::error!("Rename failed: {}", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user