diff --git a/notes.org b/notes.org index 852f60e..c966b68 100644 --- a/notes.org +++ b/notes.org @@ -1,6 +1,6 @@ #+title: Notes -* TODO show errors with ariadne +* DONE show errors with ariadne :PROPERTIES: :EFFORT: 10min :END: @@ -36,7 +36,13 @@ CLOCK: [2025-05-03 sam. 21:30]--[2025-05-03 sam. 21:50] => 0:20 :LOGBOOK: CLOCK: [2025-05-03 sam. 21:51]--[2025-05-03 sam. 21:54] => 0:03 :END: -** TODO deduplicate error display code +** DONE deduplicate error display code +:PROPERTIES: +:EFFORT: 10 +:END: +:LOGBOOK: +CLOCK: [2025-05-03 sam. 21:55]--[2025-05-03 sam. 22:01] => 0:06 +:END: * DONE snapshot testing ** DONE Find the snapshot testing library diff --git a/src/error_display.rs b/src/error_display.rs index ffaae9e..048c1dd 100644 --- a/src/error_display.rs +++ b/src/error_display.rs @@ -1,48 +1,17 @@ -use crate::{ - command::CommandParseError, meta_commands::MetaCommandParseError, - statements::StatementParseError, -}; +use crate::command::CommandParseError; use ariadne::{Color, Label, 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() - 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(); - } -} - -impl OSDBError for StatementParseError { - fn display(&self, file: &str, input: &str) { - 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(); - } -} - 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), - } + 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)) + .finish() + .print((file, Source::from(input))) + .unwrap(); } }