From e9898e49329c3364c78dff24a2ff02a2ab1ec3ff Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 29 Sep 2025 11:12:03 +0200 Subject: [PATCH] Improve error message when failing to run egui_demo_app (#7567) --- crates/egui_demo_app/src/main.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/crates/egui_demo_app/src/main.rs b/crates/egui_demo_app/src/main.rs index 48825715..37a235e8 100644 --- a/crates/egui_demo_app/src/main.rs +++ b/crates/egui_demo_app/src/main.rs @@ -8,7 +8,7 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; // Much faster allocator, can give 20% speedups: https://github.com/emilk/egui/pull/7029 // When compiling natively: -fn main() -> eframe::Result { +fn main() { for arg in std::env::args().skip(1) { match arg.as_str() { "--profile" => { @@ -62,11 +62,27 @@ fn main() -> eframe::Result { ..Default::default() }; - eframe::run_native( + let result = eframe::run_native( "egui demo app", options, Box::new(|cc| Ok(Box::new(egui_demo_app::WrapApp::new(cc)))), - ) + ); + + match result { + Ok(()) => {} + Err(err) => { + // This produces a nicer error message than returning the `Result`: + print_error_and_exit(&err); + } + } +} + +fn print_error_and_exit(err: &eframe::Error) -> ! { + #![expect(clippy::print_stderr)] + #![expect(clippy::exit)] + + eprintln!("Error: {err}"); + std::process::exit(1) } #[cfg(feature = "puffin")]