refactor(error): deduplicate error display code
This commit is contained in:
parent
fe6573b2de
commit
825511a515
2 changed files with 15 additions and 40 deletions
10
notes.org
10
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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue