From 5a79cede015272bb0d0b20e423775c97a162ded3 Mon Sep 17 00:00:00 2001 From: Artemy Date: Thu, 11 Aug 2022 17:11:07 +0300 Subject: [PATCH] fix: replace info.message() to info.payload() --- src/interpreter.rs | 12 ++++++------ src/main.rs | 11 ++++++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/interpreter.rs b/src/interpreter.rs index 7e6ac50..95f1ba9 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -219,8 +219,10 @@ impl Interpreter { fn input(&self, value: &String) -> Value { let mut input = String::new(); print!("{}", value); - io::stdout().flush().unwrap_or_default(); - io::stdin().read_line(&mut input).unwrap_or_default(); + io::stdout().flush().expect("Couldn't flush Stdout"); + io::stdin() + .read_line(&mut input) + .expect("Couldn't read from Stdin"); Value::String(input.trim_end().to_string()) } @@ -625,24 +627,22 @@ impl Interpreter { std::process::exit(1); } fn unk_token(&self, name: &str) { - println!( + panic!( "\n{} {} | {} {}", "Unexpected token name:".red(), name.bold().black(), "pos:".green(), self.pos ); - std::process::exit(1); } fn error(&self, name: &str) { - println!( + panic!( "\n{} {} | {} {}", "Error:".red(), name.bold().black(), "pos:".green(), self.pos ); - std::process::exit(1); } } diff --git a/src/main.rs b/src/main.rs index 812ec7c..2bbb186 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,8 +15,17 @@ mod interpreter; use interpreter::Interpreter; fn main() { - let start = Instant::now(); + std::panic::set_hook(Box::new(|info| { + eprint!( + "{msg}", + msg = match info.payload().downcast_ref::() { + None => "Program panicked without a message!".to_owned(), + Some(x) => x.to_string(), + } + ); + })); + let start = Instant::now(); let args = Args::parse(); if args.verbose == true { println!("Running: {}\n", args.file);