Skip to content

Commit f0f3969

Browse files
prefere panic over exit
1 parent 25f0776 commit f0f3969

4 files changed

Lines changed: 13 additions & 20 deletions

File tree

desktop/bundle/src/common.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(target_os = "linux", allow(unused))] // TODO: Remove this when bundling for linux is implemented
2+
13
use std::error::Error;
24
use std::fs;
35
use std::path::{Path, PathBuf};
@@ -45,7 +47,7 @@ pub(crate) fn build_bin(package: &str, bin: Option<&str>) -> Result<PathBuf, Box
4547
pub(crate) fn run_command(program: &str, args: &[&str]) -> Result<(), Box<dyn std::error::Error>> {
4648
let status = Command::new(program).args(args).stdout(Stdio::inherit()).stderr(Stdio::inherit()).status()?;
4749
if !status.success() {
48-
std::process::exit(1);
50+
panic!("Command '{}' with args {:?} failed with status: {}", program, args, status);
4951
}
5052
Ok(())
5153
}

desktop/bundle/src/linux.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use std::error::Error;
2-
31
use crate::common::*;
42

5-
pub fn main() -> Result<(), Box<dyn Error>> {
3+
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
64
let app_bin = build_bin("graphite-desktop-platform-linux", None)?;
75

86
// TODO: Implement bundling for linux
@@ -11,7 +9,7 @@ pub fn main() -> Result<(), Box<dyn Error>> {
119
if std::env::args().any(|a| a == "open") {
1210
run_command(&app_bin.to_string_lossy(), &[]).expect("failed to open app");
1311
} else {
14-
println!("Binary built and placed at {}", app_bin.to_string_lossy());
12+
eprintln!("Binary built and placed at {}", app_bin.to_string_lossy());
1513
eprintln!("Bundling for Linux is not yet implemented.");
1614
eprintln!("You can still start the app with the `open` subcommand. `cargo run -p graphite-desktop-bundle -- open`");
1715
std::process::exit(1);

desktop/src/cef/context/builder.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ impl<H: CefEventHandler> CefContextBuilder<H> {
138138
});
139139
}
140140
Err(e) => {
141-
tracing::error!("Failed to initialize CEF context: {:?}", e);
142-
std::process::exit(1);
141+
panic!("Failed to initialize CEF context: {:?}", e);
143142
}
144143
});
145144

desktop/src/lib.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::consts::APP_LOCK_FILE_NAME;
55
use crate::event::CreateAppEventSchedulerEventLoopExt;
66
use clap::Parser;
77
use std::io::Write;
8-
use std::process::exit;
98
use tracing_subscriber::EnvFilter;
109
use winit::event_loop::EventLoop;
1110

@@ -46,8 +45,7 @@ pub fn start() {
4645
.truncate(true)
4746
.open(dirs::app_data_dir().join(APP_LOCK_FILE_NAME))
4847
else {
49-
tracing::error!("Failed to open lock file, Exiting.");
50-
exit(1);
48+
panic!("Failed to open lock file.")
5149
};
5250
let mut lock = fd_lock::RwLock::new(lock_file);
5351
let lock = match lock.try_write() {
@@ -60,7 +58,7 @@ pub fn start() {
6058
}
6159
Err(_) => {
6260
tracing::error!("Another instance is already running, Exiting.");
63-
exit(1);
61+
std::process::exit(1);
6462
}
6563
};
6664

@@ -87,20 +85,16 @@ pub fn start() {
8785
context
8886
}
8987
Err(cef::InitError::AlreadyRunning) => {
90-
tracing::error!("Another instance is already running, Exiting.");
91-
exit(1);
88+
panic!("Another instance is already running.");
9289
}
9390
Err(cef::InitError::InitializationFailed(code)) => {
94-
tracing::error!("Cef initialization failed with code: {code}");
95-
exit(1);
91+
panic!("Cef initialization failed with code: {code}");
9692
}
9793
Err(cef::InitError::BrowserCreationFailed) => {
98-
tracing::error!("Failed to create CEF browser");
99-
exit(1);
94+
panic!("Failed to create CEF browser");
10095
}
10196
Err(cef::InitError::RequestContextCreationFailed) => {
102-
tracing::error!("Failed to create CEF request context");
103-
exit(1);
97+
panic!("Failed to create CEF request context");
10498
}
10599
};
106100

@@ -139,7 +133,7 @@ pub fn start() {
139133
// Calling `exit` bypasses rust teardown and lets Windows perform process cleanup.
140134
// TODO: Identify and fix the underlying CEF shutdown issue so this workaround can be removed.
141135
#[cfg(target_os = "windows")]
142-
exit(0);
136+
std::process::exit(0);
143137
}
144138

145139
pub fn start_helper() {

0 commit comments

Comments
 (0)