# Dry::Struct::Error not showing all errors

**URL:** https://discourse.dry-rb.org/t/dry-struct-error-not-showing-all-errors/526
**Category:** Support
**Created:** [April 4, 2018, 8:57am UTC](https://discourse.dry-rb.org/t/dry-struct-error-not-showing-all-errors/526 "2018-04-04T08:57:11Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![xero88](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/xero88/32/247_2.png) [@xero88](https://discourse.dry-rb.org/u/xero88)
#### Post date: [April 4, 2018, 8:57am UTC](https://discourse.dry-rb.org/t/dry-struct-error-not-showing-all-errors/526/1 "2018-04-04T08:57:11Z")

</div>

I have a Company object like that :

```
class Company < Dry::Struct
  constructor_type(:strict_with_defaults)

  LegalForms = Types::Strict::String.enum('SA')

  attribute :name, Types::Strict::String
  attribute :legal_form, LegalForms

end 

```

It’s there a way to show ALL types errors ?

When I do :

`Company.new`

It show only the **first** type error (name here)

> ([Company.new] :name is missing in Hash input)

I want something like :

> [Company.new] :name is missing in Hash input, :legal\_form is missing in Hash input

---

<div class="post-metadata">

### Author: ![flash-gordon](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/flash-gordon/32/494_2.png) [@flash-gordon](https://discourse.dry-rb.org/u/flash-gordon)
#### Post date: [April 4, 2018, 9:20pm UTC](https://discourse.dry-rb.org/t/dry-struct-error-not-showing-all-errors/526/2 "2018-04-04T21:20:50Z")

</div>

Hm, structs are not intended for this, you should use dry-validation to validate your data. However, the message could be improved, probably. Can you file an issue to the dry-types repo on github? I’d have a look this weekend.

---

<div class="post-metadata">

### Author: ![xero88](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/xero88/32/247_2.png) [@xero88](https://discourse.dry-rb.org/u/xero88)
#### Post date: [April 5, 2018, 6:52am UTC](https://discourse.dry-rb.org/t/dry-struct-error-not-showing-all-errors/526/3 "2018-04-05T06:52:43Z")

</div>

Hi, thank you for your answer @flash-gordon and sorry if this is “noobs” questions.

The thing that I don’t understand, it’s why do we have to separate the validation ? Is this not an anti-pattern ? With separated validation, we could have invalid object ?

> **[Invalid Object Is An Anti-Pattern](https://solnic.codes/2015/12/28/invalid-object-is-an-anti-pattern/)**
>
> The idea of an object that validates its own state has been made very popular by Rails’ ActiveRecord. We can see this pattern in many places, not only in ORM libraries but in many other gems whenever some sort of validation is needed.
> Have you ever...

> When something is possible, it means it’s going to happen.

---

<div class="post-metadata">

### Author: ![timriley](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/timriley/32/25_2.png) [@timriley](https://discourse.dry-rb.org/u/timriley)
#### Post date: [April 5, 2018, 11:38am UTC](https://discourse.dry-rb.org/t/dry-struct-error-not-showing-all-errors/526/4 "2018-04-05T11:38:35Z")

</div>

You’re right, @xero88, a validation result object _can_ be invalid, but this is actually the _purpose_ of these objects, they’re dedicated to modelling a validation result, valid or otherwise.

In this way, they actually allow us to avoid this anti-pattern, because when we have an invalid validation result, we won’t attempt to create a domain model object with that invalid data. (domain model objects are the kind that solnic was suggesting should never be created with invalid state)

---

<div class="post-metadata">

### Author: ![xero88](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/xero88/32/247_2.png) [@xero88](https://discourse.dry-rb.org/u/xero88)
#### Post date: [April 5, 2018, 11:44am UTC](https://discourse.dry-rb.org/t/dry-struct-error-not-showing-all-errors/526/5 "2018-04-05T11:44:13Z")

</div>

Ok, I understand what you mean here.  
But the dry-validation Schema must be in the object Company then ? or no ?

---

<div class="post-metadata">

### Author: ![timriley](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/timriley/32/25_2.png) [@timriley](https://discourse.dry-rb.org/u/timriley)
#### Post date: [April 5, 2018, 12:02pm UTC](https://discourse.dry-rb.org/t/dry-struct-error-not-showing-all-errors/526/6 "2018-04-05T12:02:45Z")

</div>

The schema should be separate from the domain object, and it should be as close to the “edge” of your application as possible, i.e. as close to the place where you’re accepting user/foreign input. In typical web apps, this means being close to the form. You’ll want to run the form submission through the schema before doing anything else with that data (e.g. choosing to create a domain model from it or not).
