feat(error): display location of error
This commit is contained in:
parent
51569d3ec2
commit
fe6573b2de
2 changed files with 21 additions and 4 deletions
|
|
@ -2,7 +2,7 @@ use crate::{
|
|||
command::CommandParseError, meta_commands::MetaCommandParseError,
|
||||
statements::StatementParseError,
|
||||
};
|
||||
use ariadne::{Report, ReportKind, Source};
|
||||
use ariadne::{Color, Label, Report, ReportKind, Source};
|
||||
|
||||
pub trait OSDBError {
|
||||
fn display(&self, file: &str, input: &str);
|
||||
|
|
@ -10,8 +10,13 @@ pub trait OSDBError {
|
|||
|
||||
impl OSDBError for MetaCommandParseError {
|
||||
fn display(&self, file: &str, input: &str) {
|
||||
Report::build(ReportKind::Error, (file, 0..input.len()))
|
||||
Report::build(ReportKind::Error, (file, 0..input.len() - 1))
|
||||
.with_message(format!("{self}"))
|
||||
.with_label(
|
||||
Label::new((file, 0..input.len() - 1))
|
||||
.with_color(Color::Red)
|
||||
.with_message("here"),
|
||||
)
|
||||
.finish()
|
||||
.print((file, Source::from(input)))
|
||||
.unwrap();
|
||||
|
|
@ -20,8 +25,13 @@ impl OSDBError for MetaCommandParseError {
|
|||
|
||||
impl OSDBError for StatementParseError {
|
||||
fn display(&self, file: &str, input: &str) {
|
||||
Report::build(ReportKind::Error, (file, 0..input.len()))
|
||||
Report::build(ReportKind::Error, (file, 0..input.len() - 1))
|
||||
.with_message(format!("{self}"))
|
||||
.with_label(
|
||||
Label::new((file, 0..input.len() - 1))
|
||||
.with_color(Color::Red)
|
||||
.with_message("here"),
|
||||
)
|
||||
.finish()
|
||||
.print((file, Source::from(input)))
|
||||
.unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue