Skip to main content

Error

Struct Error 

Source
pub struct Error { /* private fields */ }
Expand description

An error that can occur in this crate.

The most common type of error is a result of overflow. But other errors exist as well:

  • Time zone database lookup failure.
  • Configuration problem. (For example, trying to round a span with calendar units without providing a relative datetime.)
  • An I/O error as a result of trying to open a time zone database from a directory via TimeZoneDatabase::from_dir.
  • Parse errors.

§Introspection is limited

Other than implementing the core::error::Error, core::fmt::Debug and core::fmt::Display traits, this error type currently provides very limited introspection capabilities. Simple predicates like Error::is_range are provided, but the predicates are not exhaustive. That is, there exist some errors that do not return true for any of the Error::is_* predicates.

§Design

This crate follows the “One True God Error Type Pattern,” where only one error type exists for a variety of different operations. This design was chosen after attempting to provide finer grained error types. But finer grained error types proved difficult in the face of composition.

More about this design choice can be found in a GitHub issue about error types.

Implementations§

Source§

impl Error

Source

pub fn from_args<'a>(message: Arguments<'a>) -> Error

Creates a new error value from core::fmt::Arguments.

It is expected to use format_args! from Rust’s standard library (available in core) to create a core::fmt::Arguments.

Callers should generally use their own error types. But in some circumstances, it can be convenient to manufacture a Jiff error value specifically.

§Core-only environments

In core-only environments without a dynamic memory allocator, error messages may be degraded in some cases. For example, if the given core::fmt::Arguments could not be converted to a simple borrowed &str, then this will ignore the input given and return an “unknown” Jiff error.

§Example
use jiff::Error;

let err = Error::from_args(format_args!("something failed"));
assert_eq!(err.to_string(), "something failed");
Source

pub fn is_range(&self) -> bool

Returns true when this error originated as a result of a value being out of Jiff’s supported range.

§Example
use jiff::civil::Date;

assert!(Date::new(2025, 2, 29).unwrap_err().is_range());
assert!("2025-02-29".parse::<Date>().unwrap_err().is_range());
assert!(Date::strptime("%Y-%m-%d", "2025-02-29").unwrap_err().is_range());
Source

pub fn is_invalid_parameter(&self) -> bool

Returns true when this error originated as a result of an invalid configuration of parameters to a function call.

This particular error category is somewhat nebulous, but it’s generally meant to cover errors that could have been statically prevented by Jiff with more types in its API. Instead, a smaller API is preferred.

§Example: invalid rounding options
use jiff::{SpanRound, ToSpan, Unit};

let span = 44.seconds();
let err = span.round(
    SpanRound::new().smallest(Unit::Second).increment(45),
).unwrap_err();
// Rounding increments for seconds must divide evenly into `60`.
// But `45` does not. Thus, this is a "configuration" error.
assert!(err.is_invalid_parameter());
§Example: invalid units

One cannot round a span between dates to units less than days:

use jiff::{civil::date, Unit};

let date1 = date(2025, 3, 18);
let date2 = date(2025, 12, 21);
let err = date1.until((Unit::Hour, date2)).unwrap_err();
assert!(err.is_invalid_parameter());

Similarly, one cannot round a span between times to units greater than hours:

use jiff::{civil::time, Unit};

let time1 = time(9, 39, 0, 0);
let time2 = time(17, 0, 0, 0);
let err = time1.until((Unit::Day, time2)).unwrap_err();
assert!(err.is_invalid_parameter());
Source

pub fn is_crate_feature(&self) -> bool

Returns true when this error originated as a result of an operation failing because an appropriate Jiff crate feature was not enabled.

§Example
ⓘ
use jiff::tz::TimeZone;

// This passes when the `tz-system` crate feature is NOT enabled.
assert!(TimeZone::try_system().unwrap_err().is_crate_feature());
Source

pub fn io_error(&self) -> Option<&Error>

Returns a reference to this error’s corresponding I/O error, if it exists.

An I/O error can occur, for example, when opening a time zone database via TimeZoneDatabase::from_dir.

Trait Implementations§

Source§

impl Clone for Error

Source§

fn clone(&self) -> Error

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Error for Error

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Replaced by Error::source.
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<BoundsError> for Error

Source§

fn from(err: BoundsError) -> Error

Converts to this type from the input type.
Source§

impl From<CrateFeatureError> for Error

Source§

fn from(err: CrateFeatureError) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Error

Converts to this type from the input type.
Source§

impl From<ErrorKind> for Error

Source§

fn from(kind: ErrorKind) -> Error

Converts to this type from the input type.
Source§

impl From<FormatError> for Error

Source§

fn from(err: FormatError) -> Error

Converts to this type from the input type.
Source§

impl From<OsStrUtf8Error> for Error

Source§

fn from(err: OsStrUtf8Error) -> Error

Converts to this type from the input type.
Source§

impl From<ParseError> for Error

Source§

fn from(err: ParseError) -> Error

Converts to this type from the input type.
Source§

impl From<ParseFractionError> for Error

Source§

fn from(err: ParseFractionError) -> Error

Converts to this type from the input type.
Source§

impl From<ParseIntError> for Error

Source§

fn from(err: ParseIntError) -> Error

Converts to this type from the input type.
Source§

impl From<RoundingIncrementError> for Error

Source§

fn from(err: RoundingIncrementError) -> Error

Converts to this type from the input type.
Source§

impl From<SpecialBoundsError> for Error

Source§

fn from(err: SpecialBoundsError) -> Error

Converts to this type from the input type.
Source§

impl From<UnitConfigError> for Error

Source§

fn from(err: UnitConfigError) -> Error

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Forget for Error

§

impl Freeze for Error
where *const ArcInner<ErrorInner> is !null: Freeze, PhantomData<ArcInner<ErrorInner>>: Freeze,

§

impl Move for Error

§

impl Send for Error
where Arc<ErrorInner>: Send,

§

impl Sync for Error
where Arc<ErrorInner>: Sync,

§

impl Unpin for Error
where Arc<ErrorInner>: Unpin,

§

impl UnsafeUnpin for Error
where *const ArcInner<ErrorInner> is !null: UnsafeUnpin, PhantomData<ArcInner<ErrorInner>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> Fake for T

Source§

fn fake<U>(&self) -> U
where Self: FakeBase<U>,

Source§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where R: RngExt + ?Sized, Self: FakeBase<U>,

Source§

impl<T> FillValue<Option<T>> for T
where T: Send + 'static,

Source§

async fn fill(self) -> Result<Option<T>, Error>

Resolves the column’s value. Read more
Source§

impl<T> FillValue<T> for T
where T: Send + 'static,

Source§

async fn fill(self) -> Result<T, Error>

Resolves the column’s value. Read more
Source§

impl<K> ForeignKey<K> for K

Source§

fn key(&self) -> Option<&K>

Returns the key, or None when the field holds no key.
Source§

fn __from_key(key: K) -> K

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoMarkdown for T
where T: Display,

Source§

fn into_markdown(self) -> Markdown

The value as Slack markdown.
Source§

fn __format(self, format: impl FnOnce(&dyn Display) -> String) -> Markdown

Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T, N> NotifiedBy<T> for N
where T: Notification<N>,

Source§

fn __routes(&self) -> Vec<Route>

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, V> UpdateValue<T> for V
where V: FillValue<T>,

Source§

fn __update<M, U>(self, column: Column<M, T>, update: U) -> U
where M: Model, U: Updates<M>, T: IntoExpr + Clone + Send + Sync + 'static,

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more