-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve error message when returning non Lucky::Response #1086
Conversation
0b418b3
to
c50cf85
Compare
else | ||
redirect Home::Index | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a specific example for when there is a nil returned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same ❤️
html IndexPage, users: UserQuery.new | ||
redirect to: Home::Index | ||
json({name: "James"}) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an example here too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I liked your realistic example above instead of showing all possible options. I think showing a different example could be good, but I think it should still work if it's an example. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good point!
src/lucky/renderable.cr
Outdated
# This is a hack to force Crystal to regenerate this method for | ||
# each action. That way @type refers to the action with the problem, | ||
# and not the first action to be compiled. | ||
{% @type %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @asterite for the tip! And thanks @jwoertink for digging into this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed because type is mentioned a bit below.
I think type need to be mentioned in the method that calls this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in perform_action
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♂ I happened to check this with an action that worked with the broken version. Thanks @asterite. Will give that a shot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm this caused a compiler bug:
BUG: trying to downcast SignUps::New <- BrowserAction (Exception)
web | from Crystal::CodeGenVisitor#downcast_distinct<LLVM::Value, Crystal::Type+, Crystal::Type+>:NoReturn
But I think I had an idea that might work...we'll see :P
else | ||
redirect Home::Index | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it
html IndexPage, users: UserQuery.new | ||
redirect to: Home::Index | ||
json({name: "James"}) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I liked your realistic example above instead of showing all possible options. I think showing a different example could be good, but I think it should still work if it's an example. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet! It'll be nice to have this in. Especially in larger apps. Since it's hard to test macros, if it all works for you, then I'm good with it. 👍
src/lucky/renderable.cr
Outdated
{% | ||
raise <<-ERROR | ||
|
||
|
||
Your action returned #{T} | ||
#{@type} returned #{T} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this what we had before and it didn't work? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I was being dumb https://github.com/luckyframework/lucky/pull/1086/files#r403641754
And I couldn't figure out a way to get around it because there was a crystal bug in the compiler. Doing what Ary suggested did work when you didn't return a Lucky::Response, but when you the compiler blew up 🤷♂ So I guess this is still not possible. I think I'll keep the other changes and leave the other issue open for one day when we can do what we'd like or figure out a workaround :P
src/lucky/renderable.cr
Outdated
For example... | ||
|
||
get "/users" do | ||
# Render html, json, or redirect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Render html, json, or redirect | |
# Return one of html, json, or redirect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noice
else | ||
redirect Home::Index | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reviews!
src/lucky/renderable.cr
Outdated
{% | ||
raise <<-ERROR | ||
|
||
|
||
Your action returned #{T} | ||
#{@type} returned #{T} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I was being dumb https://github.com/luckyframework/lucky/pull/1086/files#r403641754
And I couldn't figure out a way to get around it because there was a crystal bug in the compiler. Doing what Ary suggested did work when you didn't return a Lucky::Response, but when you the compiler blew up 🤷♂ So I guess this is still not possible. I think I'll keep the other changes and leave the other issue open for one day when we can do what we'd like or figure out a workaround :P
src/lucky/renderable.cr
Outdated
For example... | ||
|
||
get "/users" do | ||
# Render html, json, or redirect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noice
html IndexPage, users: UserQuery.new | ||
redirect to: Home::Index | ||
json({name: "James"}) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good point!
07caa51
to
3f1dc36
Compare
Closes #1037 And improves error message
3f1dc36
to
91b736e
Compare
Closes#460 #1086 (comment)Closes #1037 and adds examples