luckyframework / lucky

A full-featured Crystal web framework that catches bugs for you, runs incredibly fast, and helps you write code that lasts.
https://luckyframework.org
MIT License
2.57k stars 156 forks source link

Needs needs a better error message #1714

Open jwoertink opened 1 year ago

jwoertink commented 1 year ago

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.