Skip to content

Commit

Permalink
refactor process exit status handling with error codes
Browse files Browse the repository at this point in the history
The code was changed to refactor the process exit status handling. This change was made due to the #![feature(exit_status_error)] feature not being stable yet. The new code now retrieves the exit code from the exit status and falls back to a custom error code (7900) if it's unavailable. A debug message is added to log the process exit code. The code then checks for non-zero exit codes and a specific error code (-1073740791), indicating the process was forcefully killed, in which case it won't bail. Otherwise, it raises an error with the non-zero exit code.
  • Loading branch information
1zun4 committed Jul 17, 2023
1 parent 4d1ef3d commit 6395159
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(exit_status_error)]
// #![feature(exit_status_error)] - wait for feature to be stable
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
Expand Down
10 changes: 8 additions & 2 deletions src-tauri/src/minecraft/java/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use std::path::{Path, PathBuf};
use std::process::Stdio;
use tokio::sync::oneshot::Receiver;
use tokio::process::{Child, Command};
use anyhow::Result;
use anyhow::{Result, bail};
use tokio::io::AsyncReadExt;
use tracing::debug;
pub struct JavaRuntime(PathBuf);

impl JavaRuntime {
Expand Down Expand Up @@ -47,7 +48,12 @@ impl JavaRuntime {
break;
},
exit_status = running_task.wait() => {
exit_status?.exit_ok()?;
let code = exit_status?.code().unwrap_or(7900); // 7900 = unwrap failed error code

debug!("Process exited with code: {}", code);
if code != 0 && code != -1073740791 { // -1073740791 = happens when the process is killed forcefully, we don't want to bail in this case
bail!("Process exited with non-zero code: {}", code);
}
break;
},
}
Expand Down
1 change: 0 additions & 1 deletion src-tauri/src/minecraft/rule_interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::collections::HashSet;

use anyhow::Result;
use regex::Regex;
use tracing::debug;

use crate::minecraft::version::{Rule, RuleAction};
use crate::utils::{OS, ARCHITECTURE, OS_VERSION};
Expand Down

0 comments on commit 6395159

Please sign in to comment.