refactor(error_display): generic display method for error types
this is to better support ariadne in the future
This commit is contained in:
parent
e841a1779e
commit
6910407ad2
4 changed files with 43 additions and 1 deletions
14
notes.org
Normal file
14
notes.org
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#+title: Notes
|
||||||
|
|
||||||
|
* show errors with ariadne
|
||||||
|
:PROPERTIES:
|
||||||
|
:EFFORT: 10min
|
||||||
|
:END:
|
||||||
|
** errors should have a generic show() function
|
||||||
|
:PROPERTIES:
|
||||||
|
:EFFORT: 10min
|
||||||
|
:END:
|
||||||
|
:LOGBOOK:
|
||||||
|
CLOCK: [2025-05-03 sam. 18:40]--[2025-05-03 sam. 18:46] => 0:06
|
||||||
|
:END:
|
||||||
|
** OSDBError::display() should take a filename and display it alongside the error
|
||||||
26
src/error_display.rs
Normal file
26
src/error_display.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
use crate::{
|
||||||
|
command::CommandParseError, meta_commands::MetaCommandParseError,
|
||||||
|
statements::StatementParseError,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub trait OSDBError {
|
||||||
|
fn display(&self);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OSDBError for MetaCommandParseError {
|
||||||
|
fn display(&self) {
|
||||||
|
println!("{self}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OSDBError for StatementParseError {
|
||||||
|
fn display(&self) {
|
||||||
|
println!("{self}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OSDBError for CommandParseError {
|
||||||
|
fn display(&self) {
|
||||||
|
println!("{self}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
pub mod branding;
|
pub mod branding;
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
pub mod command;
|
pub mod command;
|
||||||
|
pub mod error_display;
|
||||||
pub mod meta_commands;
|
pub mod meta_commands;
|
||||||
pub mod statements;
|
pub mod statements;
|
||||||
pub mod tokens;
|
pub mod tokens;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use osdb::branding::startup_msg;
|
use osdb::branding::startup_msg;
|
||||||
use osdb::cli::read_input;
|
use osdb::cli::read_input;
|
||||||
use osdb::command::Command;
|
use osdb::command::Command;
|
||||||
|
use osdb::error_display::OSDBError as _;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
startup_msg();
|
startup_msg();
|
||||||
|
|
@ -12,7 +13,7 @@ fn main() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => eprintln!("{err}"),
|
Err(err) => err.display(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue