osdb/src/error_display.rs

18 lines
557 B
Rust
Raw Normal View History

use crate::command::CommandParseError;
2025-05-03 21:55:06 +02:00
use ariadne::{Color, Label, Report, ReportKind, Source};
pub trait OSDBError {
fn display(&self, file: &str, input: &str);
}
impl OSDBError for CommandParseError {
fn display(&self, file: &str, input: &str) {
2025-05-03 21:55:06 +02:00
Report::build(ReportKind::Error, (file, 0..input.len() - 1))
.with_message(self.message())
.with_label(Label::new((file, 0..input.len() - 1)).with_color(Color::Red))
.finish()
.print((file, Source::from(input)))
.unwrap();
}
}