csf-dev/CSF.Validation

As a dev, I would like to treat exceptions whilst accessing values as validation failures, instead of ignoring the exception

Closed this issue · 1 comments

Currently, there is logic to ignore exceptions caught when using accessors. This allows a container to avoid an accessor that throws from bringing the whole validator down.

This comes with a downside though, which is that the value is then treated as valid, because no validation can be performed on the value of that accessor.

What I'd like to do is to enhance that so that it's possible to ignore the exception, but to add an additional validation failure too essentially say "this accessor threw", and treat that as invalid.

Actually, I don't think I wasn't treat it as a failure. I think I'd prefer an Error result added to the validation result, and all validation rules for the value (or its children) are skipped.

This brings me to three available behaviours:

  • Just throw when an exception occurs (halts validation)
  • Record an Error result amongst the validation but otherwise continue
  • Ignore the exception entirely

Those second two behaviours would still mean that rules for the value (and any derived values) would not be executed. There's no way to execute these no matter what.