luckyframework/lucky_record

Type restrictions on Form constructors to prevent opaque errors when initializing a form with the incorrect parameters

robacarp opened this issue · 1 comments

I recently received the runtime stack trace:

Nil assertion failed at src/forms/user/account_form.cr:1 (Exception)
  from /usr/local/Cellar/crystal/0.27.0/src/nil.cr:107:5 in 'not_nil!'
  from src/actions/my/update.cr:0:1 in 'call'

The problem turned out to be that I was calling AccountForm.update(params) instead of AccountForm.update(model_object, params). It’s obviously my mistake, but the opaque compiler error made an adventure out of debugging it because the error was very distant from the code which triggered the runtime exception.

Adding a type restriction here would prevent this opaque error and force the compiler to provide a more helpful error message.

Closed by #307