impl ScriptError::from for types BotError and PoisonError
This commit is contained in:
parent
7e01186178
commit
b86a8f4a52
@ -2,14 +2,14 @@ pub mod application;
|
|||||||
pub mod db;
|
pub mod db;
|
||||||
pub mod message_info;
|
pub mod message_info;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Mutex;
|
use std::sync::{Mutex, PoisonError};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::db::raw_calls::RawCallError;
|
use crate::db::raw_calls::RawCallError;
|
||||||
use crate::db::{CallDB, DbError, User, DB};
|
use crate::db::{CallDB, DbError, User, DB};
|
||||||
use crate::message_answerer::MessageAnswererError;
|
use crate::message_answerer::MessageAnswererError;
|
||||||
use crate::notify_admin;
|
|
||||||
use crate::utils::parcelable::{ParcelType, Parcelable, ParcelableError, ParcelableResult};
|
use crate::utils::parcelable::{ParcelType, Parcelable, ParcelableError, ParcelableResult};
|
||||||
|
use crate::{notify_admin, BotError};
|
||||||
use chrono::{DateTime, Days, NaiveTime, ParseError, TimeDelta, Timelike, Utc};
|
use chrono::{DateTime, Days, NaiveTime, ParseError, TimeDelta, Timelike, Utc};
|
||||||
use db::attach_db_obj;
|
use db::attach_db_obj;
|
||||||
use futures::future::join_all;
|
use futures::future::join_all;
|
||||||
@ -48,6 +48,23 @@ pub enum ScriptError {
|
|||||||
MutexError(String),
|
MutexError(String),
|
||||||
#[error("can't send message to user to user: {0:?}")]
|
#[error("can't send message to user to user: {0:?}")]
|
||||||
MAError(#[from] MessageAnswererError),
|
MAError(#[from] MessageAnswererError),
|
||||||
|
#[error("other script error: {0:?}")]
|
||||||
|
Other(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<BotError> for ScriptError {
|
||||||
|
fn from(value: BotError) -> Self {
|
||||||
|
match value {
|
||||||
|
crate::BotError::DBError(db_error) => ScriptError::DBError(db_error),
|
||||||
|
error => ScriptError::Other(format!("BotError: {error}")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> From<PoisonError<T>> for ScriptError {
|
||||||
|
fn from(value: PoisonError<T>) -> Self {
|
||||||
|
Self::MutexError(format!("Can't lock Mutex in script, err: {}", value))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user