Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message when passing a string and expecting an array #49

Open
esanmiguelc opened this issue Feb 11, 2020 · 0 comments
Open

Comments

@esanmiguelc
Copy link

Problem

# Example ImmutableStruct

Example = ImmutableStruct.new([:name])

Example.new(name: "somestring")
# => NoMethodError (undefined method `to_a' for "somestring":String)

Potential solution:

Check if we can call #to_a on the object that we are receiving. If we cannot, continue to fail but provide a more helpful message around what failed and how to fix it. Proposed language:

Expected Array for property: :name, Got: String

This one maintains the current API and behavior.

Alternative solution

Instead of using Object#to_a use Array(Object) which will wrap the object in an array or no-op if it's already an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant