Skip to content

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

@esanmiguelc

Description

@esanmiguelc

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions