osdb/src/error_display.rs

39 lines
1.1 KiB
Rust
Raw Normal View History

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) {
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) {
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) {
match self {
CommandParseError::MetaCommand(err) => err.display(file, input),
CommandParseError::Statement(err) => err.display(file, input),
}
}
}