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

@ -29,7 +29,14 @@ CLOCK: [2025-05-03 sam. 21:28]--[2025-05-03 sam. 21:30] => 0:02
:LOGBOOK:
CLOCK: [2025-05-03 sam. 21:30]--[2025-05-03 sam. 21:50] => 0:20
:END:
** TODO error display should include a span to show where the error occured
** DONE error display should include a span to show where the error occured
:PROPERTIES:
:EFFORT: 10
:END:
:LOGBOOK:
CLOCK: [2025-05-03 sam. 21:51]--[2025-05-03 sam. 21:54] => 0:03
:END:
** TODO deduplicate error display code
* DONE snapshot testing
** DONE Find the snapshot testing library

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