# Dry::Types::Struct non-empty string attribute

**URL:** <https://discourse.dry-rb.org/t/dry-types-struct-non-empty-string-attribute/104>\
**Category:** dry-types\
**Created:** [August 23, 2016, 2:20pm UTC](https://discourse.dry-rb.org/t/dry-types-struct-non-empty-string-attribute/104 "2016-08-23T14:20:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pvmeerbe](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@pvmeerbe](https://discourse.dry-rb.org/u/pvmeerbe)\
**Post date:** [August 23, 2016, 2:20pm UTC](https://discourse.dry-rb.org/t/dry-types-struct-non-empty-string-attribute/104/1 "2016-08-23T14:20:24Z")

</div>

Hi All,

I was wondering how one could ensure that a Dry::Types::Struct attribute is a non-blank string.

I was able to get this behavior with

```
class MyClass < Dry::Types::Struct

     attribute :name, Types::Strict::String.constrained( format: /\S/) # contains at least one non-whitespace character
end

```

However this triggers a very unclear error message & I did not find a way to specify a more specific error string.

```
 MyClass.new(name: ' ')
  --> Dry::Types::StructError: [MyClass.new] " " (String) has invalid type for :name

```

kind regards  
Pieter

---

<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:** [August 25, 2016, 5:24am UTC](https://discourse.dry-rb.org/t/dry-types-struct-non-empty-string-attribute/104/2 "2016-08-25T05:24:04Z")

</div>

This would be the sort of error message to expect for dry-types’ behaviour as it stands right now.

It looks like you’ve got your type set up to do what you like, anyway? If you’d like to open a discussion about improving error messages for struct initialization, I’d encourage you to go ahead and open an issue over at [http://github.com/dry-rb/dry-struct/](http://github.com/dry-rb/dry-struct/), which is where future development of the structs will be happening 🙂

---

<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:** [August 25, 2016, 9:47am UTC](https://discourse.dry-rb.org/t/dry-types-struct-non-empty-string-attribute/104/3 "2016-08-25T09:47:20Z")

</div>

Yes it’s been on my todo list for a long time - improve type error handling in structs. I’ll get to it at some point. This is one of the reasons why I wanted to extract Struct into dry-struct, since this project needs more code and more attention and shouldn’t be part of dry-types.
