feat(errors): display basic errors with ariadne
This commit is contained in:
parent
4246775db5
commit
51569d3ec2
4 changed files with 52 additions and 7 deletions
23
Cargo.lock
generated
23
Cargo.lock
generated
|
|
@ -2,6 +2,16 @@
|
|||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "ariadne"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "36f5e3dca4e09a6f340a61a0e9c7b61e030c69fc27bf29d73218f7e5e3b7638f"
|
||||
dependencies = [
|
||||
"unicode-width",
|
||||
"yansi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "console"
|
||||
version = "0.15.11"
|
||||
|
|
@ -47,6 +57,7 @@ checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
|||
name = "osdb"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ariadne",
|
||||
"insta",
|
||||
]
|
||||
|
||||
|
|
@ -56,6 +67,12 @@ version = "2.7.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.59.0"
|
||||
|
|
@ -128,3 +145,9 @@ name = "windows_x86_64_msvc"
|
|||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
|
||||
[[package]]
|
||||
name = "yansi"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049"
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ edition = "2024"
|
|||
authors = ["Khaïs COLIN"]
|
||||
|
||||
[dependencies]
|
||||
ariadne = "0.5.1"
|
||||
|
||||
[dev-dependencies]
|
||||
insta = "1.43.1"
|
||||
|
|
|
|||
11
notes.org
11
notes.org
|
|
@ -22,7 +22,14 @@ CLOCK: [2025-05-03 sam. 21:24]--[2025-05-03 sam. 21:28] => 0:04
|
|||
:LOGBOOK:
|
||||
CLOCK: [2025-05-03 sam. 21:28]--[2025-05-03 sam. 21:30] => 0:02
|
||||
:END:
|
||||
** TODO OSDBError::display() should generate ariadne errors and return those
|
||||
** DONE OSDBError::display() should generate ariadne errors and return those
|
||||
:PROPERTIES:
|
||||
:EFFORT: 10
|
||||
:END:
|
||||
: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 snapshot testing
|
||||
|
||||
** DONE Find the snapshot testing library
|
||||
|
|
@ -99,3 +106,5 @@ CLOCK: [2025-05-03 sam. 21:21]--[2025-05-03 sam. 21:22] => 0:01
|
|||
:LOGBOOK:
|
||||
CLOCK: [2025-05-03 sam. 19:06]--[2025-05-03 sam. 19:07] => 0:01
|
||||
:END:
|
||||
|
||||
* TODO switch statement parsing to more extensible token-based algorithm
|
||||
|
|
|
|||
|
|
@ -2,25 +2,37 @@ use crate::{
|
|||
command::CommandParseError, meta_commands::MetaCommandParseError,
|
||||
statements::StatementParseError,
|
||||
};
|
||||
use ariadne::{Report, ReportKind, Source};
|
||||
|
||||
pub trait OSDBError {
|
||||
fn display(&self, file: &str, input: &str);
|
||||
}
|
||||
|
||||
impl OSDBError for MetaCommandParseError {
|
||||
fn display(&self, file: &str, _input: &str) {
|
||||
println!("{file}: {self}")
|
||||
fn display(&self, file: &str, input: &str) {
|
||||
Report::build(ReportKind::Error, (file, 0..input.len()))
|
||||
.with_message(format!("{self}"))
|
||||
.finish()
|
||||
.print((file, Source::from(input)))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
impl OSDBError for StatementParseError {
|
||||
fn display(&self, file: &str, _input: &str) {
|
||||
println!("{file}: {self}")
|
||||
fn display(&self, file: &str, input: &str) {
|
||||
Report::build(ReportKind::Error, (file, 0..input.len()))
|
||||
.with_message(format!("{self}"))
|
||||
.finish()
|
||||
.print((file, Source::from(input)))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
impl OSDBError for CommandParseError {
|
||||
fn display(&self, file: &str, _input: &str) {
|
||||
println!("{file}: {self}")
|
||||
fn display(&self, file: &str, input: &str) {
|
||||
match self {
|
||||
CommandParseError::MetaCommand(err) => err.display(file, input),
|
||||
CommandParseError::Statement(err) => err.display(file, input),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue