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