fix: replace info.message() to info.payload()

This commit is contained in:
Artemy 2022-08-11 17:11:07 +03:00
parent b5970aaac6
commit 5a79cede01
2 changed files with 16 additions and 7 deletions

View file

@ -219,8 +219,10 @@ impl Interpreter {
fn input(&self, value: &String) -> Value { fn input(&self, value: &String) -> Value {
let mut input = String::new(); let mut input = String::new();
print!("{}", value); print!("{}", value);
io::stdout().flush().unwrap_or_default(); io::stdout().flush().expect("Couldn't flush Stdout");
io::stdin().read_line(&mut input).unwrap_or_default(); io::stdin()
.read_line(&mut input)
.expect("Couldn't read from Stdin");
Value::String(input.trim_end().to_string()) Value::String(input.trim_end().to_string())
} }
@ -625,24 +627,22 @@ impl Interpreter {
std::process::exit(1); std::process::exit(1);
} }
fn unk_token(&self, name: &str) { fn unk_token(&self, name: &str) {
println!( panic!(
"\n{} {} | {} {}", "\n{} {} | {} {}",
"Unexpected token name:".red(), "Unexpected token name:".red(),
name.bold().black(), name.bold().black(),
"pos:".green(), "pos:".green(),
self.pos self.pos
); );
std::process::exit(1);
} }
fn error(&self, name: &str) { fn error(&self, name: &str) {
println!( panic!(
"\n{} {} | {} {}", "\n{} {} | {} {}",
"Error:".red(), "Error:".red(),
name.bold().black(), name.bold().black(),
"pos:".green(), "pos:".green(),
self.pos self.pos
); );
std::process::exit(1);
} }
} }

View file

@ -15,8 +15,17 @@ mod interpreter;
use interpreter::Interpreter; use interpreter::Interpreter;
fn main() { fn main() {
let start = Instant::now(); std::panic::set_hook(Box::new(|info| {
eprint!(
"{msg}",
msg = match info.payload().downcast_ref::<String>() {
None => "Program panicked without a message!".to_owned(),
Some(x) => x.to_string(),
}
);
}));
let start = Instant::now();
let args = Args::parse(); let args = Args::parse();
if args.verbose == true { if args.verbose == true {
println!("Running: {}\n", args.file); println!("Running: {}\n", args.file);