# Dry-v feature suggestion: returning an array, not a hash, from errors

**URL:** <https://discourse.dry-rb.org/t/dry-v-feature-suggestion-returning-an-array-not-a-hash-from-errors/166>\
**Category:** dry-validation\
**Created:** [November 25, 2016, 4:43pm UTC](https://discourse.dry-rb.org/t/dry-v-feature-suggestion-returning-an-array-not-a-hash-from-errors/166 "2016-11-25T16:43:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![georgemillo](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/georgemillo/32/69_2.png) [@georgemillo](https://discourse.dry-rb.org/u/georgemillo)\
**Post date:** [November 25, 2016, 4:43pm UTC](https://discourse.dry-rb.org/t/dry-v-feature-suggestion-returning-an-array-not-a-hash-from-errors/166/1 "2016-11-25T16:43:00Z")

</div>

In ActiveModel if you call `errors.full_messages`, you get an Array, e.g.:

```ruby
model.errors.full_messages # => ["Age must be present", "Age must be at least 18", "Name must be 20 characters or less"]

```

This means I can do something simple like this in my ERB:

```auto
<ul>
  <% @model.errors.full_messages.each do |msg| %>
    <li><%= msg %></li>
  <% end %>
</ul>

```

Whereas dry-v’s (errors: true) returns a hash, something like:

```ruby
result.errors(full: true)
# => {age: ["age must be present", "age must be at least 18"], name: ["name must be 20 characters or less"]}

```

Which means my ERB has to get more complicated:

```auto
<ul>
  <% @form.errors(full: true).each do |_, msgs| %>
    <% msgs.each do |msg| %>
      <li><%= msg %></li>
    <% end %>
  <% end %>
</ul>

```

Life would be easier (and it would ease my transition from ActiveModel to dry-v) if I could pass an option to `errors` which makes it return an array of full messages:

```ruby
result.errors(full: true, flat: true)
# => ["age must be present", "age must be at least 18", "name must be 20 characters or less"]

```

Would you accept this feature if I added it?

---

<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:** [November 26, 2016, 11:22am UTC](https://discourse.dry-rb.org/t/dry-v-feature-suggestion-returning-an-array-not-a-hash-from-errors/166/2 "2016-11-26T11:22:23Z")

</div>

Yes this sounds like a good addition. I gotta be honest that I don’t remember why it was decided to use a hash for full messages 😕

---

<div class="post-metadata">

**Author:** ![georgemillo](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/georgemillo/32/69_2.png) [@georgemillo](https://discourse.dry-rb.org/u/georgemillo)\
**Post date:** [November 27, 2016, 4:34pm UTC](https://discourse.dry-rb.org/t/dry-v-feature-suggestion-returning-an-array-not-a-hash-from-errors/166/3 "2016-11-27T16:34:37Z")

</div>

Well in that case, if you don’t mind the breaking change how about changing it so that `(full: true)` simply returns an array?

I can’t think of any use case where I’d want to get “full” messages as a hash.

---

<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:** [December 2, 2016, 10:31am UTC](https://discourse.dry-rb.org/t/dry-v-feature-suggestion-returning-an-array-not-a-hash-from-errors/166/4 "2016-12-02T10:31:54Z")

</div>

Yes I’m OK with that. Please report an issue and I’ll schedule it for 1.0.0 release.

---

<div class="post-metadata">

**Author:** ![georgemillo](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/georgemillo/32/69_2.png) [@georgemillo](https://discourse.dry-rb.org/u/georgemillo)\
**Post date:** [December 5, 2016, 4:54pm UTC](https://discourse.dry-rb.org/t/dry-v-feature-suggestion-returning-an-array-not-a-hash-from-errors/166/5 "2016-12-05T16:54:32Z")

</div>

Done: [https://github.com/dry-rb/dry-validation/issues/286](https://github.com/dry-rb/dry-validation/issues/286)
