Skip to content

Conversation

@BurntSushi
Copy link
Owner

This PR adds three predicates to jiff::Error:

  • is_range returns true when the error was caused by a value going
    out of Jiff's supported range.
  • is_crate_feature returns true when the error was caused by a Jiff
    crate feature not being enabled.
  • is_invalid_parameter returns true when the error was caused by some
    kind of illegal configuration in a function call. e.g., Trying to round
    the span between two Timestamp values to the nearest year.

There is probably more introspection that we could do, but I think this
should cover the more immediate need.

Closes #418

We previously only used this in the `core::fmt::Display` trait
implementation, so we just inlined it there. But we'll want to use it to
get the root of the chain for error predicates, so this commit does some
refactoring to provide a standalone internal iterator for the error
chain.
I'm somewhat concerned that this doesn't cover all cases, but I think
this should be a good start.
There's only a few of these, but they seem like a distinct category
from other error types. It's also nice to do this and standarize on the
specific error message.

The other reason I wanted to do this was to distinguish it from a
possible "is configuration error" category. (e.g., Trying to round a
span to the nearest year without a relative datatime.) These could also
be seen as configuration errors, but I want them to be in a separate
category I think.
@BurntSushi BurntSushi merged commit a50f679 into master Dec 22, 2025
40 checks passed
@BurntSushi BurntSushi deleted the ag/error-predicates branch December 22, 2025 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add "error kind" predicates on jiff::Error

2 participants