feat(error): display location of error

This commit is contained in:
Khaïs COLIN 2025-05-03 21:55:06 +02:00
parent 51569d3ec2
commit fe6573b2de
2 changed files with 21 additions and 4 deletions

View file

@ -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();