Generic Errors object

Hey everyone, happy new year! :sunny:

We at Trailblazer are wondering whether it’d make sense to establish an generic Errors object that can be used in Dry.rb, Rails and TRB. In Rails 6.1, there’s an approach here ActiveModel::Errors and in Dry.rb I’ve discovered MessageSet and friends.

The API would be something along errors.add, errors[:field] and errors.messages.

Background of this idea is we are introducing a stack-wide Errors object in TRB that is passed through operations and contracts and “enriched” with error messages on the way. As a matter of fact, we want this object’s API to be as close to Rails and Dry.rb as possible.

Is this something anyone would be interested in discussing? I don’t think it’s a big thing, and we’d love to use something DRY.rb in our code, as we won’t be using ActiveModel::Errors most definitely.

Hey hey, Happy New Year :slightly_smiling_face:

Yes unifying this would be nice. What are the requirements?

Hey guys!

We’re facing a related challange here.

A dry-transaction’s step can returns a Failure containing any kind of object.

  • In a moment can be a Dry::Schema::MessageSet as a result from Dry::Schema.Params validation.
  • In other moment can be a simple Hash from a arbitrary Failure({error: '...'}) from a step.
  • Could be a String from a arbitrary Failure('my error') from a step.
  • Could be a StandardError (or its subclasses) from a try step adapter
  • Could be an ActiveRecord validation error.

Would great to have a well defined object shape, so the errors could easily handled in our controllers and other kind of consumers of dry-transaction.