validate icon indicating copy to clipboard operation
validate copied to clipboard

all() passes validation even when a rule throws an error

Open grimmjulian opened this issue 6 months ago • 2 comments

Hi, thanks for the great package! It really helps a lot.

I’ve been using the all() and any() validation functions and encountered some unexpected behavior:

When one of the rules inside the confrontation object throws an error (e.g., due to missing column), the overall validation still passes. I would expect that in such cases, the validation should fail, since an error likely means something went wrong with the check.

val <- validator(a >0)
out <- confront(women, val)
all(out)
# TRUE

Would love to know if this is intentional — and if not, whether you'd consider changing the behavior so that errors within rules cause the overall validation to fail.

Thanks again!

grimmjulian avatar May 28 '25 19:05 grimmjulian

All statements about the empty set are true. So I think formally this is correct behavior, even though it is maybe counterintuitive

You can set the raise option to ensure that confront crashes on a failing rule.

markvanderloo avatar Jun 06 '25 21:06 markvanderloo

Thanks for your reply, and sorry for my late response.

I’m not looking to make confront() crash — I’d just like to use the validation result in an if clause and be able to tell if any of the rules failed or errored. Right now, the all() function can return TRUE even if some rules failed to evaluate, which is a bit misleading in that context.

If the default behavior will not be changed, another argument can be included that checks returns FALSE for an error validation? all and any have already the na.rm argument, so maybe something similar like fail_on_error or error.rm can be included. I will try to make PR for that to see if that is acceptable.

grimmjulian avatar Jun 18 '25 08:06 grimmjulian