1use std::error::Error;
4use std::fmt;
5use std::num::TryFromIntError;
6use time::error::ComponentRange;
7
8pub type Result<T> = std::result::Result<T, EpochError>;
9
10#[derive(Debug)]
12pub struct EpochError {
13 pub err: String,
14}
15
16impl EpochError {
17 pub fn numeric_precision(err: &str) -> Self {
19 Self {
20 err: format!("A numeric precision error occurred: {}", err),
21 }
22 }
23}
24
25impl fmt::Display for EpochError {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 write!(f, "epoch-cli error: {}", self.err)
28 }
29}
30
31impl Error for EpochError {}
32
33impl From<ComponentRange> for EpochError {
35 fn from(err: ComponentRange) -> Self {
36 Self {
37 err: err.to_string(),
38 }
39 }
40}
41
42impl From<TryFromIntError> for EpochError {
44 fn from(err: TryFromIntError) -> Self {
45 Self {
46 err: err.to_string(),
47 }
48 }
49}