How to deal with "warnings" instead of "errors"?

Hey everyone :wave:,

First of all, I’m sorry if my question sounds a bit off-topic, I could not find anything related to that anywhere but I might miss the official concept wording. If that’s the case please point me in the right direction so I can RTFM!

I have a working contract with a simple schema and some rules.
It happens that I now need to display a “warning” to my users, it sounds extremely natural to keep using rules to do that as I believe it’s still validation logic.

Pseudo code would give something like:

rule(:description) do
  key.warning("should be at least 256 characters") if value.length < 256
end

# which could then be used following the same pattern
contract.call(description: "blablabla").warnings.to_h # => {:description=>["should be at least..."]}

# this rule does not imply an error so it's still a success
contract.call(description: "blablabla").success? # => true

I understand it’s not possible to do that with dry-validation and I have done a first pass on the code to see if I could find a workaround but did not manage to.

Do you know if there is a way to actually do that or something close? Or any advice on where to put that to not end up with more spaghetti code? Or… is this just a really bad idea? :smiley:

Thank you for your time,
JB

1 Like

I see the reason why you could need it before t unfortunately don’t know the “right” solution.

What I would do, is to have error messages starting from “warning:”, which would allow you to easily filter them out.

You could then have an extension to a result object to add filtering methods for your needs.

But this is just a quick idea, let me know if it inspires you somewhat :).