Skip to content

Commit

Permalink
Improve errors
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamRagstad committed Nov 2, 2024
1 parent 42a4940 commit d0adf55
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/commands/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use lento_core::{
type_checker::types::GetType,
};

use crate::{error::print_error, CLI_VERSION};
use crate::{
error::{print_parse_error, print_runtime_error},
CLI_VERSION,
};

pub fn handle_command_repl(args: &ArgMatches, _arg_parser: &mut Command) {
// Set the Ctrl-C handler to exit the program
Expand Down Expand Up @@ -63,13 +66,13 @@ pub fn handle_command_repl(args: &ArgMatches, _arg_parser: &mut Command) {
}
}
Err(err) => {
print_error(err.message);
print_runtime_error(err.message);
break 'exprs; // Stop on error
}
}
}
}
Err(err) => print_error(err.message),
Err(err) => print_parse_error(err.message),
}
// Instead of creating a new parser, lexer, and reader, we simply reset them to save memory
parser.lexer().reset();
Expand Down
8 changes: 8 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
use clap::Command;
use colorful::Colorful;

pub fn print_parse_error(msg: String) {
println!("{}: {}\n", "parse error".light_red(), msg);
}

pub fn print_runtime_error(msg: String) {
println!("{}: {}\n", "runtime error".light_red(), msg);
}

pub fn print_error(msg: String) {
println!("{}: {}\n", "error".light_red(), msg);
}
Expand Down

0 comments on commit d0adf55

Please sign in to comment.