#![allow(clippy::std_instead_of_core)]
use core::{fmt::Display, result::Result as StdResult};
use std::io;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error
{
#[error(transparent)]
Decimal(#[from] rust_decimal::Error),
#[error("There was an error decoding {context}: {reason}")]
Decode
{
context: String,
reason: String,
},
#[error(transparent)]
Io(#[from] io::Error),
#[error(transparent)]
Reqwest(#[from] reqwest::Error),
#[error("The {0} currency is not supported. See https://docs.rs/money2/latest/money2/type.Currency.html for a list of supported currencies")]
UnsupportedCurrency(String),
#[error(transparent)]
Zip(#[from] zip::result::ZipError),
}
impl Error
{
pub(crate) fn csv_row_missing<D>(row: D) -> Self
where
D: Display,
{
Self::Decode {
context: "the exchange rates CSV from the ECB".into(),
reason: format!("there was no {row} row"),
}
}
}
pub type Result<T> = StdResult<T, Error>;