Skip to contents

Runs a validator against a value and returns the validation messages instead of raising an error. Every step is checked (as with .on_fail = "all"), so all violations are reported in one pass.

Usage

validation_errors(validator, value, ...)

Arguments

validator

a restriction object created by restrict().

value

the value to validate.

...

context arguments passed to the validator (e.g. newdata = df), the same as a direct validator call.

Value

A character vector of failure messages, or character(0) if the value satisfies every step. Each element is the full path-aware message for one failing step.

Details

Only validation failures are caught. A usage error, such as a missing context dependency declared by a formula step, still propagates so the calling mistake is not silently reported as invalid data.

Examples

v <- restrict("x") |> require_numeric() |> require_positive()
validation_errors(v, 5)       # character(0)
#> character(0)
validation_errors(v, c(-1))   # one message
#> [1] "x: must be non-negative\n  Found: -1"