Files
desubot/src/errors.rs

103 lines
2.9 KiB
Rust
Raw Normal View History

use mystem::AppError as mystem_error;
2020-12-05 15:57:11 +03:00
use reqwest::Error as reqwest_error;
2020-11-29 16:23:27 +03:00
use rusqlite::Error as sqlite_error;
2020-12-06 23:55:09 +03:00
use serde_json::Error as serde_error;
2020-12-07 15:55:25 +03:00
use std::{fmt, io::Error as io_error};
2020-12-10 14:46:19 +03:00
use subprocess::PopenError as popen_error;
2020-12-07 15:55:25 +03:00
use telegram_bot::Error as tg_error;
2020-11-29 16:23:27 +03:00
#[derive(Debug)]
2020-12-10 14:46:19 +03:00
pub enum Error {
2020-11-29 16:23:27 +03:00
UserNotFound,
SQLITE3Error(sqlite_error),
TelegramError(tg_error),
2020-12-05 15:57:11 +03:00
ReqwestError(reqwest_error),
2020-11-29 16:23:27 +03:00
ConfNotFound,
2020-12-07 15:55:25 +03:00
WordNotFound,
WordInStopList,
2020-12-05 15:57:11 +03:00
IOError(io_error),
FileNotFound,
2020-12-06 23:55:09 +03:00
JsonParseError(serde_error),
2020-12-10 14:46:19 +03:00
PopenError(popen_error),
MystemError(mystem_error),
2021-01-05 03:30:21 +03:00
SQLBannedCommand(String),
2021-01-03 22:37:37 +03:00
SQLInvalidCommand,
2021-01-05 03:30:21 +03:00
SQLResultTooLong(String),
2021-01-08 17:32:39 +03:00
CodeHighlightningError,
2020-11-29 16:23:27 +03:00
}
2021-01-05 03:30:21 +03:00
2020-11-29 16:23:27 +03:00
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "An error occurred.")
2021-01-08 17:32:39 +03:00
// match self {
// _ => write!(f, "An error occurred."),
// // Error::UserNotFound => {}
// // Error::SQLITE3Error(_) => {}
// // Error::TelegramError(_) => {}
// // Error::ReqwestError(_) => {}
// // Error::ConfNotFound => {}
// // Error::WordNotFound => {}
// // Error::WordInStopList => {}
// // Error::IOError(_) => {}
// // Error::FileNotFound => {}
// // Error::JsonParseError(_) => {}
// // Error::PopenError(_) => {}
// // Error::MystemError(_) => {}
// // Error::SQLBannedCommand(_) => {}
// // Error::SQLInvalidCommand => {}
// // Error::SQLResultTooLong(_) => {}
// // Error::CodeHighlightningError(Help) => write!(f, "Code highlighter.\
// // <b>Usage</b><pre>/CODE\
// // #&lt;theme&gt;\
// // &lt;CODE&gt;\
// // #&lt;lang&gt;</pre>\
// // \
// // List of themes:\
// // .")
// Error::CodeHighlightningError(help) => write!(f, "{}", help.description)
// }
2020-11-29 16:23:27 +03:00
}
}
impl From<sqlite_error> for Error {
fn from(e: sqlite_error) -> Error {
2021-01-05 05:14:44 +03:00
Error::SQLITE3Error(e)
2020-11-29 16:23:27 +03:00
}
}
impl From<tg_error> for Error {
fn from(e: tg_error) -> Error {
2021-01-05 05:14:44 +03:00
Error::TelegramError(e)
2020-11-29 16:23:27 +03:00
}
2020-12-05 15:57:11 +03:00
}
impl From<reqwest_error> for Error {
fn from(e: reqwest_error) -> Error {
2021-01-05 05:14:44 +03:00
Error::ReqwestError(e)
2020-12-05 15:57:11 +03:00
}
}
impl From<io_error> for Error {
fn from(e: io_error) -> Error {
2021-01-05 05:14:44 +03:00
Error::IOError(e)
2020-12-05 15:57:11 +03:00
}
2020-12-06 23:55:09 +03:00
}
impl From<serde_error> for Error {
fn from(e: serde_error) -> Error {
2021-01-05 05:17:22 +03:00
Error::JsonParseError(e)
2020-12-06 23:55:09 +03:00
}
}
2020-12-10 14:46:19 +03:00
impl From<popen_error> for Error {
fn from(e: popen_error) -> Error {
2021-01-05 05:17:22 +03:00
Error::PopenError(e)
2020-12-10 14:46:19 +03:00
}
}
impl From<mystem_error> for Error {
fn from(e: mystem_error) -> Error {
2021-01-05 05:17:22 +03:00
Error::MystemError(e)
}
}