From 4246775db558a5ea56704607897aea5f6bb257e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Sat, 3 May 2025 21:29:40 +0200 Subject: [PATCH] refactor(errors): error display function takes an input string to be able to resolve spans in the future --- notes.org | 10 ++++++++-- src/error_display.rs | 8 ++++---- src/main.rs | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/notes.org b/notes.org index 05e6c16..00cd0a9 100644 --- a/notes.org +++ b/notes.org @@ -13,9 +13,15 @@ CLOCK: [2025-05-03 sam. 18:40]--[2025-05-03 sam. 18:46] => 0:06 :END: ** DONE OSDBError::display() should take a filename and display it alongside the error :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: -** 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 * DONE snapshot testing diff --git a/src/error_display.rs b/src/error_display.rs index 57a1bdf..3cc2a3d 100644 --- a/src/error_display.rs +++ b/src/error_display.rs @@ -4,23 +4,23 @@ use crate::{ }; pub trait OSDBError { - fn display(&self, file: &str); + fn display(&self, file: &str, input: &str); } impl OSDBError for MetaCommandParseError { - fn display(&self, file: &str) { + fn display(&self, file: &str, _input: &str) { println!("{file}: {self}") } } impl OSDBError for StatementParseError { - fn display(&self, file: &str) { + fn display(&self, file: &str, _input: &str) { println!("{file}: {self}") } } impl OSDBError for CommandParseError { - fn display(&self, file: &str) { + fn display(&self, file: &str, _input: &str) { println!("{file}: {self}") } } diff --git a/src/main.rs b/src/main.rs index 99063ea..5757d01 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ fn main() { break; } } - Err(err) => err.display(""), + Err(err) => err.display("", &input), } } println!("Good-bye");