feat(errors): display basic errors with ariadne
This commit is contained in:
parent
4246775db5
commit
51569d3ec2
4 changed files with 52 additions and 7 deletions
|
|
@ -2,25 +2,37 @@ use crate::{
|
|||
command::CommandParseError, meta_commands::MetaCommandParseError,
|
||||
statements::StatementParseError,
|
||||
};
|
||||
use ariadne::{Report, ReportKind, Source};
|
||||
|
||||
pub trait OSDBError {
|
||||
fn display(&self, file: &str, input: &str);
|
||||
}
|
||||
|
||||
impl OSDBError for MetaCommandParseError {
|
||||
fn display(&self, file: &str, _input: &str) {
|
||||
println!("{file}: {self}")
|
||||
fn display(&self, file: &str, input: &str) {
|
||||
Report::build(ReportKind::Error, (file, 0..input.len()))
|
||||
.with_message(format!("{self}"))
|
||||
.finish()
|
||||
.print((file, Source::from(input)))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
impl OSDBError for StatementParseError {
|
||||
fn display(&self, file: &str, _input: &str) {
|
||||
println!("{file}: {self}")
|
||||
fn display(&self, file: &str, input: &str) {
|
||||
Report::build(ReportKind::Error, (file, 0..input.len()))
|
||||
.with_message(format!("{self}"))
|
||||
.finish()
|
||||
.print((file, Source::from(input)))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
impl OSDBError for CommandParseError {
|
||||
fn display(&self, file: &str, _input: &str) {
|
||||
println!("{file}: {self}")
|
||||
fn display(&self, file: &str, input: &str) {
|
||||
match self {
|
||||
CommandParseError::MetaCommand(err) => err.display(file, input),
|
||||
CommandParseError::Statement(err) => err.display(file, input),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue