2020-12-29 17:01:56 +03:00
|
|
|
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),
|
2020-12-29 17:01:56 +03:00
|
|
|
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),
|
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.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return Error::JsonParseError(e);
|
|
|
|
}
|
|
|
|
}
|
2020-12-10 14:46:19 +03:00
|
|
|
|
|
|
|
impl From<popen_error> for Error {
|
|
|
|
fn from(e: popen_error) -> Error {
|
|
|
|
return Error::PopenError(e);
|
|
|
|
}
|
|
|
|
}
|
2020-12-29 17:01:56 +03:00
|
|
|
|
|
|
|
impl From<mystem_error> for Error {
|
|
|
|
fn from(e: mystem_error) -> Error {
|
|
|
|
return Error::MystemError(e);
|
|
|
|
}
|
|
|
|
}
|