Skip to content

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Sep 2, 2024
1 parent 752be03 commit 1803d2e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ fn main() {
fn run() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<String> = env::args().collect();
if args.len() != 2 {
eprintln!("Usage: {} <program_path>", args[0]);
std::process::exit(1);
return Err("Invalid arguments".into());
}
let exe_path = env::current_exe()?;
let exe_dir = exe_path
Expand All @@ -28,13 +27,18 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
let params = content.trim();
let mut cmd = Command::new(&args[1]);
cmd.arg(params);
cmd.spawn().expect("Failed to start program");
if let Err(e) = cmd.spawn() {
return Err(format!("Failed to start program\n{}\n{}\n{}", e, &args[1], params).into());
}
Ok(())
}

fn show_error(message: &str) {
let wide: Vec<u16> = OsStr::new(message).encode_wide().chain(Some(0)).collect();
let title: Vec<u16> = OsStr::new("Error").encode_wide().chain(Some(0)).collect();
let title: Vec<u16> = OsStr::new("Mihomo Party Runner")
.encode_wide()
.chain(Some(0))
.collect();
unsafe {
MessageBoxW(std::ptr::null_mut(), wide.as_ptr(), title.as_ptr(), 0);
}
Expand Down

0 comments on commit 1803d2e

Please sign in to comment.