# Generic Errors object

**URL:** https://discourse.dry-rb.org/t/generic-errors-object/1417
**Category:** Ideas
**Created:** [January 12, 2022, 12:36pm UTC](https://discourse.dry-rb.org/t/generic-errors-object/1417 "2022-01-12T12:36:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![apotonick](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/apotonick/32/737_2.png) [@apotonick](https://discourse.dry-rb.org/u/apotonick)
#### Post date: [January 12, 2022, 12:36pm UTC](https://discourse.dry-rb.org/t/generic-errors-object/1417/1 "2022-01-12T12:36:01Z")

</div>

Hey everyone, happy new year! ☀

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](https://api.rubyonrails.org/classes/ActiveModel/Errors.html) 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.

---

<div class="post-metadata">

### Author: ![solnic](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/solnic/32/779_2.png) [@solnic](https://discourse.dry-rb.org/u/solnic)
#### Post date: [January 17, 2022, 8:12am UTC](https://discourse.dry-rb.org/t/generic-errors-object/1417/2 "2022-01-17T08:12:50Z")

</div>

Hey hey, Happy New Year 🙂

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

---

<div class="post-metadata">

### Author: ![theo-bittencourt](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/theo-bittencourt/32/906_2.png) [@theo-bittencourt](https://discourse.dry-rb.org/u/theo-bittencourt)
#### Post date: [July 31, 2023, 6:59pm UTC](https://discourse.dry-rb.org/t/generic-errors-object/1417/3 "2023-07-31T18:59:43Z")

</div>

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.
