You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.3 KiB
103 lines
2.3 KiB
use backtrace::Backtrace as CrateBacktrace; |
|
use diesel::result::Error as DslError; |
|
#[cfg(not(target_arch = "wasm32"))] |
|
use reqwest::Error as ReqError; |
|
use serde::{Deserialize, Serialize}; |
|
use std::fmt; |
|
use thiserror::Error; |
|
use uuid::Uuid; |
|
|
|
pub type UResult<T> = std::result::Result<T, UErrorBt>; |
|
pub type ULocalResult<T> = std::result::Result<T, ULocalError>; |
|
|
|
#[derive(Error, Debug, Serialize, Deserialize, Clone)] |
|
pub struct UErrorBt { |
|
pub err: UError, |
|
pub backtrace: String, |
|
} |
|
|
|
impl fmt::Display for UErrorBt { |
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
|
write!(f, "{}\nBACKTRACE: \n{:?}", self.err, self.backtrace) |
|
} |
|
} |
|
|
|
impl From<UError> for UErrorBt { |
|
fn from(err: UError) -> UErrorBt { |
|
UErrorBt { |
|
err, |
|
backtrace: format!("{:?}", CrateBacktrace::new()), |
|
} |
|
} |
|
} |
|
|
|
#[derive(Error, Debug, Serialize, Deserialize, Clone)] |
|
pub enum UError { |
|
#[error("Runtime error: {0}")] |
|
Runtime(String), |
|
|
|
#[error("Connection error: {0}. Body: {1}")] |
|
NetError(String, String), |
|
|
|
#[error("Parse error")] |
|
ParseError, |
|
|
|
#[error("Job error: {0}")] |
|
JobError(String), |
|
|
|
#[error("Argument parsing failed: {0}")] |
|
JobArgsError(String), |
|
|
|
#[error("Job is uncompleted yet")] |
|
JobUncompleted, |
|
|
|
#[error("Job cannot be ran on this platform. Expected: {0}, got: {1}")] |
|
InsuitablePlatform(String, String), |
|
|
|
#[error("Job {0} doesn't exist")] |
|
NoJob(Uuid), |
|
|
|
#[error("Error while processing {0}: {1}")] |
|
FSError(String, String), |
|
|
|
#[error("Wrong auth token")] |
|
WrongToken, |
|
|
|
#[error("Panicked: {0}")] |
|
Panic(String), |
|
|
|
#[error("UI init error: {0}")] |
|
TUIError(String), |
|
} |
|
|
|
impl UError { |
|
pub fn into_bt(self) -> UErrorBt { |
|
UErrorBt::from(self) |
|
} |
|
} |
|
|
|
#[cfg(not(target_arch = "wasm32"))] |
|
impl From<ReqError> for UErrorBt { |
|
fn from(e: ReqError) -> Self { |
|
UError::from(e).into_bt() |
|
} |
|
} |
|
|
|
#[cfg(not(target_arch = "wasm32"))] |
|
impl From<ReqError> for UError { |
|
fn from(e: ReqError) -> Self { |
|
UError::NetError(e.to_string(), String::new()) |
|
} |
|
} |
|
|
|
#[derive(Error, Debug)] |
|
pub enum ULocalError { |
|
#[error("{0} is not found")] |
|
NotFound(String), |
|
|
|
#[error("Error processing {0}")] |
|
ProcessingError(String), |
|
|
|
#[error(transparent)] |
|
DBError(#[from] DslError), |
|
}
|
|
|