use chrono::{DateTime, Utc};
use std::error::Error as StdError;
use thiserror::Error;
pub(crate) type BoxDynError = Box<dyn StdError + 'static + Send + Sync>;
#[derive(Error, Debug)]
pub enum Error {
#[error("start_time `{0}` is ahead of current time")]
StartTimeAheadOfCurrentTime(DateTime<Utc>),
#[error("machine_id returned an error: {0}")]
MachineIdFailed(#[source] BoxDynError),
#[error("data_center_id returned an error: {0}")]
DataCenterIdFailed(#[source] BoxDynError),
#[error("check_machine_id returned false")]
CheckMachineIdFailed,
#[error("check_data_center_id returned false")]
CheckDataCenterIdFailed,
#[error("over the time limit")]
OverTimeLimit,
#[error("could not find any private IPv4 or IPv6 address")]
NoPrivateIP,
#[error("failed to parse SnowflakeId: {0}")]
ParseIdFailed(String),
#[error("clock drifted backward: last_time={last_time}, current_time={current_time}")]
ClockDrift {
last_time: u64,
current_time: u64,
},
#[error("clock drift {drift_ms}ms exceeded maximum allowed {max_ms}ms")]
ClockDriftExceeded {
drift_ms: u64,
max_ms: i64,
},
#[error(
"invalid bit length configuration: time({0}) + sequence({1}) + data_center({2}) + machine({3}) must be 63"
)]
InvalidBitLength(u8, u8, u8, u8),
}