# Dry::Struct: improve exception message on MissingAttributeError

**URL:** <https://discourse.dry-rb.org/t/dry-improve-exception-message-on-missingattributeerror/1300>\
**Category:** Ideas\
**Created:** [July 8, 2021, 12:52pm UTC](https://discourse.dry-rb.org/t/dry-improve-exception-message-on-missingattributeerror/1300 "2021-07-08T12:52:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![phillipoertel](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/phillipoertel/32/673_2.png) [@phillipoertel](https://discourse.dry-rb.org/u/phillipoertel)\
**Post date:** [July 8, 2021, 12:52pm UTC](https://discourse.dry-rb.org/t/dry-improve-exception-message-on-missingattributeerror/1300/1 "2021-07-08T12:52:24Z")

</div>

Hi everyone,

in our current project, we use Dry::Struct extensively. Our Dry::Structs are often nested (right now up to three levels). Here’s an example:

```ruby

module Core
  module Models
    class Claim < Dry::Struct
      attribute :policy, Core::Models::Policy
      # ...
    end
  end
end

module Core
  module Models
    class Policy < Dry::Struct
      # ...
    end
  end
end

```

When creating new instances of our structs, we often get this error:

```ruby
      Dry::Struct::MissingAttributeError:
       Missing attribute: :transport

```

Due to the nesting, and the fact that we use Dry::Struct in many places (not just the model layer) it’s  
often difficult to find out where the attribute is missing.

An improved exception message of Dry::Struct::MissingAttributeError would thus be (example):

```auto
      Dry::Struct::MissingAttributeError:
       Missing attribute: :transport on Core::Models::Claim

```

Here’s a PR to implement that: [Add class name to MissingAttributeError exception message by phillipoertel · Pull Request #170 · dry-rb/dry-struct · GitHub](https://github.com/dry-rb/dry-struct/pull/170).  
We’d be happy if you find this addition helpful too.

Cheers  
Phillip

---

<div class="post-metadata">

**Author:** ![phillipoertel](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/phillipoertel/32/673_2.png) [@phillipoertel](https://discourse.dry-rb.org/u/phillipoertel)\
**Post date:** [July 12, 2021, 3:17pm UTC](https://discourse.dry-rb.org/t/dry-improve-exception-message-on-missingattributeerror/1300/2 "2021-07-12T15:17:21Z")

</div>

Hi, any thoughts on this?

---

<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:** [July 13, 2021, 7:52am UTC](https://discourse.dry-rb.org/t/dry-improve-exception-message-on-missingattributeerror/1300/3 "2021-07-13T07:52:54Z")

</div>

Thoughts: it looks good. 🙂 We’ll merge it sometime soon, thank you. There are some other things I’d like to improve about type errors btw so I hope to bundle them.

---

<div class="post-metadata">

**Author:** ![phillipoertel](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/phillipoertel/32/673_2.png) [@phillipoertel](https://discourse.dry-rb.org/u/phillipoertel)\
**Post date:** [July 14, 2021, 10:00am UTC](https://discourse.dry-rb.org/t/dry-improve-exception-message-on-missingattributeerror/1300/4 "2021-07-14T10:00:58Z")

</div>

Cool, thank you.

---

<div class="post-metadata">

**Author:** ![phillipoertel](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/phillipoertel/32/673_2.png) [@phillipoertel](https://discourse.dry-rb.org/u/phillipoertel)\
**Post date:** [August 24, 2021, 4:48pm UTC](https://discourse.dry-rb.org/t/dry-improve-exception-message-on-missingattributeerror/1300/5 "2021-08-24T16:48:59Z")

</div>

Hi guys, I just ran across our dry-struct monkey patch to fix this issue, and was wondering if you’d add it. My PR is still available, and would merge nicely.  
Cheers, Phillip
