lucky
lucky copied to clipboard
(Re)Add helpful error message when failing to return a Lucky::Response in an action
See https://github.com/luckyframework/lucky/issues/437
It seems this may be an issue in Crystal, but I need more time to track it down. For now, I'm going to remove this special error-handling and add it back later. That's better than giving people incorrect instructions. Note that a compile-time error will still be raised, it will just be a generic Crystal error.
This would be reverted and fixed: https://github.com/luckyframework/lucky/pull/459/commits/43c2ed11913c98bf6a18a9b30ae85314d6def97d
As of crystal 0.27.2, this is still an issue. Just to clarify the issue, if you have an action Home::Index
defined like
class Home::Index < BrowserAction
get "/" do
"blah"
end
end
with this error message, you'll get something more like:
SignUps::New returned (Lucky::TextResponse | String), but it must return a Lucky::Response.
Where you would expect
Home::Index returned (Lucky::TextResponse | String), but it must return a Lucky::Response.
My guess is the #{@type}
on this line is going to be the last class to implement this method, and not the one to throw the error because it's compile time. But I tried to re-create a mini example and failed 😞
Dang :( I think I may need to open a bounty on this because it would be really nice to have this error again.
Maybe a stop gap solution could be to output the current file and line though
On Mar 19, 2019, at 6:58 PM, Jeremy Woertink [email protected] wrote:
As of crystal 0.27.2, this is still an issue. Just to clarify the issue, if you have an action Home::Index defined like
class Home::Index < BrowserAction get "/" do "blah" end end with this error message, you'll get something more like:
SignUps::New returned (Lucky::TextResponse | String), but it must return a Lucky::Response.
Where you would expect
Home::Index returned (Lucky::TextResponse | String), but it must return a Lucky::Response.
My guess is the #{@type} on this line https://github.com/luckyframework/lucky/blob/fa500736c7ca9916c2fd8e46f6a993cd9c7fe572/src/lucky/renderable.cr#L97 is going to be the last class to implement this method, and not the one to throw the error because it's compile time. But I tried to re-create a mini example and failed 😞
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/luckyframework/lucky/issues/460#issuecomment-474616588, or mute the thread https://github.com/notifications/unsubscribe-auth/AABXek_KtmrpsVQAPsvXM686qiKONYpZks5vYWuPgaJpZM4T7svs.
Tried again on Crystal 0.29 and still didn't work. Delaying until another Crystal release is out to try again with
Tried to dig in here, but as of Crystal 0.33.0 this is still an issue.
Ok, got a little insight that might help here https://forum.crystal-lang.org/t/trying-to-locate-the-proper-class-in-a-macro/1814/5
Either we figure out how to type those route methods and let the compiler handle it, or we can try that little hacky deal to see if that fixes it.