Skip to content

Describe whether a failure can be recovered from

Source: R/failure.R ยท Help: ?failure_metadata

Failure metadata is the machine-readable part of a dataexcept error: whether the underlying condition is known to be transient, permanent for the same operation and payload, or unclassified, and whether retrying the same operation can succeed. It describes the failure; it does not prescribe a retry policy, which stays with the calling code.

Usage

failure_metadata(
  kind = "unknown",
  retryable = NULL,
  retry_after_seconds = NULL
)

with_failure_metadata(cnd, metadata)

Arguments

kind
One of "unknown", "transient" or "permanent".
retryable
TRUE, FALSE, or NULL when no classification is warranted. NULL is deliberately distinct from FALSE.
retry_after_seconds
How long to wait before retrying, when the backend said: a finite, non-negative number, or NULL.
cnd
A condition object.
metadata
A dataexcept_failure_metadata object from failure_metadata().

Value

failure_metadata() returns an object of class dataexcept_failure_metadata: a list with elements kind, retryable and retry_after_seconds.

with_failure_metadata() returns cnd with the metadata attached.

Details

Every dataexcept error carries metadata. The class default is deliberately conservative ("unknown", retryable NULL), and a class receives a stronger default only where it can be defended without knowing the backend: a validation_error() is permanent and not retryable for the same unchanged payload. Code that does know the backend's answer attaches it with with_failure_metadata().

Examples

failure_metadata("transient", retryable = TRUE, retry_after_seconds = 2)

err <- api_error("https://api.example.com/v1/orders", status_code = 503L)
err <- with_failure_metadata(err, failure_metadata("transient", TRUE, 30))
is_retryable(err)

See also

condition_failure() to read the metadata back from a condition.