From 07bed9ac11e45a490cc42431747b815391b13f56 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 14 Jun 2026 14:49:57 +0000 Subject: [PATCH] Exit gracefully on unreadable input instead of panicking Replace the panics in read_input with a plain stderr message (same text as before) and a non-zero exit, so a bad file argument no longer surfaces as a Rust panic with a backtrace note. --- src/main.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2700003..b6ebf56 100644 --- a/src/main.rs +++ b/src/main.rs @@ -112,14 +112,23 @@ fn read_input(file: &Option) -> Vec { match file.as_deref() { Some(path) if path != "-" => { File::open(path) - .unwrap_or_else(|e| panic!("cannot open '{}': {}", path, e)) + .unwrap_or_else(|e| { + eprintln!("cannot open '{}': {}", path, e); + std::process::exit(1); + }) .read_to_end(&mut data) - .unwrap_or_else(|e| panic!("read error: {}", e)); + .unwrap_or_else(|e| { + eprintln!("read error: {}", e); + std::process::exit(1); + }); } _ => { io::stdin() .read_to_end(&mut data) - .unwrap_or_else(|e| panic!("read error: {}", e)); + .unwrap_or_else(|e| { + eprintln!("read error: {}", e); + std::process::exit(1); + }); } }; data