From 7b1c015d06703fb19631ab38bb42899e42c725eb Mon Sep 17 00:00:00 2001 From: Gert Pellin - GPE Date: Thu, 8 Oct 2026 13:03:03 +0200 Subject: [PATCH] Desktop: no eprintln! on the log and panic paths (#246) eprintln! panics when standard error is a broken pipe (a GUI launch on Windows), and a panic inside the panic hook aborts. The "no log file" message goes through log::warn! (standard error only by then); the panic hook's fallback writes to standard error with write_fmt and ignores the error. Follow-up to #239, same fix as storytold/vectorcraft#465. Co-authored-by: Brandon Thomas --- apps/pdfcraft/src/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/pdfcraft/src/main.rs b/apps/pdfcraft/src/main.rs index f4ced71bb8..4ac79a33c2 100644 --- a/apps/pdfcraft/src/main.rs +++ b/apps/pdfcraft/src/main.rs @@ -86,7 +86,8 @@ fn main() -> eframe::Result { if log::log_enabled!(log::Level::Error) { log::error!("{report}"); } else { - eprintln!("pdfcraft: {report}"); + // `eprintln!` panics on a broken stderr pipe, and a panic inside the panic hook aborts. + let _ = std::io::Write::write_fmt(&mut std::io::stderr(), format_args!("pdfcraft: {report}\n")); } })); let mut files = Vec::new(); @@ -132,7 +133,8 @@ fn main() -> eframe::Result { if let (Some(logger), Some(dir)) = (logger, settings_dir()) { match logger.attach_dir(&dir.join("logs")) { Ok(path) => log::info!("PdfCraft {}, log file {}", env!("CARGO_PKG_VERSION"), path.display()), - Err(e) => eprintln!("pdfcraft: no log file: {e}"), + // Standard error only by now (`attach_dir` gave up on the file); unlike `eprintln!`, never panics. + Err(e) => log::warn!("no log file: {e}"), } } let persistence_path = settings_dir().map(|d| d.join("app.ron"));