sonyflake/
error.rs

1use chrono::{DateTime, Utc};
2use std::error::Error as StdError;
3use thiserror::Error;
4
5/// Convenience type alias for usage within sonyflake.
6pub(crate) type BoxDynError = Box<dyn StdError + 'static + Send + Sync>;
7
8/// The error type for this crate.
9#[derive(Error, Debug)]
10pub enum Error {
11    /// Start time is ahead of current time
12    #[error("start_time `{0}` is ahead of current time")]
13    StartTimeAheadOfCurrentTime(DateTime<Utc>),
14    /// Maching ID fn failed.
15    #[error("machine_id returned an error: {0}")]
16    MachineIdFailed(#[source] BoxDynError),
17    /// Maching ID check failed.
18    #[error("check_machine_id returned false")]
19    CheckMachineIdFailed,
20    /// Over time limit.
21    #[error("over the time limit")]
22    OverTimeLimit,
23    /// No prive IPv4.
24    #[error("could not find any private ipv4 address")]
25    NoPrivateIPv4,
26    /// Mutex is poisoned.
27    #[error("mutex is poisoned (i.e. a panic happened while it was locked)")]
28    MutexPoisoned,
29    /// Failed to get current time.
30    #[error("failed to get current time")]
31    FailedToGetCurrentTime,
32    #[cfg(not(feature = "pnet"))]
33    /// Returned if the pnet features is deactivated an no custom machine id
34    /// function was provided.
35    #[error("no machine id function provided")]
36    NoMachineIdFn,
37}