feat(error): display location of error
This commit is contained in:
parent
51569d3ec2
commit
fe6573b2de
2 changed files with 21 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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