use serde::{Deserialize, Serialize};
use thiserror::Error;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ForecastTradeError {
DataError(String),
ModelError(String),
ForecastError(String),
StrategyError(String),
IoError(String),
ConfigError(String),
ValidationError(String),
}
#[derive(Debug, Error)]
pub enum ForecastError {
#[error("Data error: {0}")]
DataError(String),
#[error("Forecasting error: {0}")]
ForecastingError(String),
#[error("Validation error: {0}")]
ValidationError(String),
#[error("Math error: {0}")]
MathError(String),
#[error("Invalid parameter: {0}")]
InvalidParameter(String),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("Polars error: {0}")]
PolarsError(String),
#[error("Model error: {0}")]
ModelError(String),
}
pub type Result<T> = std::result::Result<T, ForecastError>;
impl From<polars::prelude::PolarsError> for ForecastError {
fn from(err: polars::prelude::PolarsError) -> Self {
ForecastError::PolarsError(err.to_string())
}
}
impl From<String> for ForecastError {
fn from(error: String) -> Self {
ForecastError::ModelError(error)
}
}
impl From<&str> for ForecastError {
fn from(error: &str) -> Self {
ForecastError::ModelError(error.to_string())
}
}
impl From<Box<dyn std::error::Error + Send + Sync>> for ForecastError {
fn from(error: Box<dyn std::error::Error + Send + Sync>) -> Self {
ForecastError::ModelError(error.to_string())
}
}