refactor(error_report): remove dead code
This commit is contained in:
parent
620259af48
commit
faedfadeab
5 changed files with 7 additions and 70 deletions
|
|
@ -210,6 +210,8 @@ i will use rustyline, since it seems like the most feature-complete
|
||||||
|
|
||||||
* DONE show marking where error occurs
|
* DONE show marking where error occurs
|
||||||
|
|
||||||
|
* DONE remove uneeded error variants
|
||||||
|
|
||||||
* TODO cli tests using insta-cmd
|
* TODO cli tests using insta-cmd
|
||||||
https://insta.rs/docs/cmd/
|
https://insta.rs/docs/cmd/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::meta_commands::{MetaCommand, MetaCommandExecuteResult, MetaCommandParseError};
|
use crate::meta_commands::{MetaCommand, MetaCommandExecuteResult};
|
||||||
use crate::statements::{Statement, StatementExecuteResult, StatementParseError};
|
use crate::statements::{Statement, StatementExecuteResult};
|
||||||
use crate::tokens::ScanError;
|
use crate::tokens::ScanError;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -49,45 +49,21 @@ impl Command {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum CommandParseError {
|
pub enum CommandParseError {
|
||||||
MetaCommand(MetaCommandParseError),
|
|
||||||
Statement(StatementParseError),
|
|
||||||
Scan(ScanError),
|
Scan(ScanError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CommandParseError {
|
|
||||||
pub(crate) fn message(&self) -> String {
|
|
||||||
match self {
|
|
||||||
CommandParseError::MetaCommand(x) => format!("{x}"),
|
|
||||||
CommandParseError::Statement(x) => format!("{x}"),
|
|
||||||
CommandParseError::Scan(x) => format!("{x}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<MetaCommand> for Command {
|
impl From<MetaCommand> for Command {
|
||||||
fn from(value: MetaCommand) -> Self {
|
fn from(value: MetaCommand) -> Self {
|
||||||
Command::MetaCommand(value)
|
Command::MetaCommand(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<MetaCommandParseError> for CommandParseError {
|
|
||||||
fn from(value: MetaCommandParseError) -> Self {
|
|
||||||
CommandParseError::MetaCommand(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Statement> for Command {
|
impl From<Statement> for Command {
|
||||||
fn from(value: Statement) -> Self {
|
fn from(value: Statement) -> Self {
|
||||||
Command::Statement(value)
|
Command::Statement(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<StatementParseError> for CommandParseError {
|
|
||||||
fn from(value: StatementParseError) -> Self {
|
|
||||||
CommandParseError::Statement(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ScanError> for CommandParseError {
|
impl From<ScanError> for CommandParseError {
|
||||||
fn from(value: ScanError) -> Self {
|
fn from(value: ScanError) -> Self {
|
||||||
CommandParseError::Scan(value)
|
CommandParseError::Scan(value)
|
||||||
|
|
|
||||||
|
|
@ -7,20 +7,8 @@ pub trait OSDBError {
|
||||||
|
|
||||||
impl OSDBError for CommandParseError {
|
impl OSDBError for CommandParseError {
|
||||||
fn display(&self, file: &str, input: &str) {
|
fn display(&self, file: &str, input: &str) {
|
||||||
if let CommandParseError::Scan(x) = self {
|
let CommandParseError::Scan(x) = self;
|
||||||
x.display(file, input);
|
x.display(file, input);
|
||||||
} else {
|
|
||||||
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)
|
|
||||||
.with_message(self.message()),
|
|
||||||
)
|
|
||||||
.finish()
|
|
||||||
.print((file, Source::from(input)))
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,6 +22,7 @@ impl OSDBError for ScanError {
|
||||||
.with_color(Color::Red)
|
.with_color(Color::Red)
|
||||||
.with_message(format!("{self}")),
|
.with_message(format!("{self}")),
|
||||||
)
|
)
|
||||||
|
.with_help("Make sure you don't have any typos or unexpected characters.")
|
||||||
.finish()
|
.finish()
|
||||||
.print((file, Source::from(input)))
|
.print((file, Source::from(input)))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
||||||
|
|
@ -14,18 +14,3 @@ impl MetaCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum MetaCommandParseError {
|
|
||||||
Unrecognized { cmd: String },
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Display for MetaCommandParseError {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
match self {
|
|
||||||
MetaCommandParseError::Unrecognized { cmd } => {
|
|
||||||
write!(f, "unrecognized meta-command {cmd:?}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -4,21 +4,6 @@ pub enum Statement {
|
||||||
Select,
|
Select,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum StatementParseError {
|
|
||||||
Unrecognized { stmt: String },
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Display for StatementParseError {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
match self {
|
|
||||||
StatementParseError::Unrecognized { stmt } => {
|
|
||||||
write!(f, "unrecognized statement {stmt:?}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct StatementExecuteResult {
|
pub struct StatementExecuteResult {
|
||||||
pub msg: String,
|
pub msg: String,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue