lucky icon indicating copy to clipboard operation
lucky copied to clipboard

Needs needs a better error message

Open jwoertink opened this issue 3 years ago • 0 comments

Related: https://github.com/luckyframework/avram/issues/850

For Shard::Field if you pass an unpermitted attribute, you'll get a poor error message just telling you "no overload matches". This is true because we do

needs attribute : PermittedAttribute

def initialize(
  @attribute : PermittedAttribute
)
end

Then we end up passing in a different type. This would be the same if we did needs id : Int32 and passed in a String.

In lib/lucky/src/lucky/mount_component.cr:32:17

 32 | component.new(*args, **named_args).view(view).context(@context).render do |*yield_args|
                ^--
Error: no overload matches 'Shared::Field(T).new' with types , attribute: Avram::Attribute(String)+, label_text: String

Overloads are:
 - Shared::Field(T).new(attribute : Avram::PermittedAttribute(T), label_text : String | ::Nil = nil, **unused_exposures)
Couldn't find overloads for these types:
 - Shared::Field(T).new(attribute : Avram::Attribute(String), label_text : String)

I think with other types, this is a bit more noticeable with Avram attributes because you know you're passing in the type you want, you just may have forgot to permit it, and using the Shared::Field hides that error.

jwoertink avatar Aug 07 '22 23:08 jwoertink