refactor(errors): error display function takes an input string to be able to resolve spans in the future

This commit is contained in:
Khaïs COLIN 2025-05-03 21:29:40 +02:00
parent 442c4b7beb
commit 4246775db5
3 changed files with 13 additions and 7 deletions

View file

@ -13,9 +13,15 @@ CLOCK: [2025-05-03 sam. 18:40]--[2025-05-03 sam. 18:46] => 0:06
:END: :END:
** DONE OSDBError::display() should take a filename and display it alongside the error ** DONE OSDBError::display() should take a filename and display it alongside the error
:LOGBOOK: :LOGBOOK:
CLOCK: [2025-05-03 sam. 21:24]--[2025-05-03 sam. 21:27] => 0:03 CLOCK: [2025-05-03 sam. 21:24]--[2025-05-03 sam. 21:28] => 0:04
:END:
** DONE OSDBError::display() should take an input string, to be able to resolve spans inside the error
:PROPERTIES:
:EFFORT: 10
:END:
:LOGBOOK:
CLOCK: [2025-05-03 sam. 21:28]--[2025-05-03 sam. 21:30] => 0:02
:END: :END:
** TODO OSDBError::display() should take an input string, to be able to resolve spans inside the error
** TODO OSDBError::display() should generate ariadne errors and return those ** TODO OSDBError::display() should generate ariadne errors and return those
* DONE snapshot testing * DONE snapshot testing

View file

@ -4,23 +4,23 @@ use crate::{
}; };
pub trait OSDBError { pub trait OSDBError {
fn display(&self, file: &str); fn display(&self, file: &str, input: &str);
} }
impl OSDBError for MetaCommandParseError { impl OSDBError for MetaCommandParseError {
fn display(&self, file: &str) { fn display(&self, file: &str, _input: &str) {
println!("{file}: {self}") println!("{file}: {self}")
} }
} }
impl OSDBError for StatementParseError { impl OSDBError for StatementParseError {
fn display(&self, file: &str) { fn display(&self, file: &str, _input: &str) {
println!("{file}: {self}") println!("{file}: {self}")
} }
} }
impl OSDBError for CommandParseError { impl OSDBError for CommandParseError {
fn display(&self, file: &str) { fn display(&self, file: &str, _input: &str) {
println!("{file}: {self}") println!("{file}: {self}")
} }
} }

View file

@ -14,7 +14,7 @@ fn main() {
break; break;
} }
} }
Err(err) => err.display("<stdin>"), Err(err) => err.display("<stdin>", &input),
} }
} }
println!("Good-bye"); println!("Good-bye");