Skip to content
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

Merged
merged 1 commit into from
Apr 5, 2020

Conversation

paulcsmith
Copy link
Member

@paulcsmith paulcsmith commented Apr 5, 2020

Closes #460 #1086 (comment)
Closes #1037 and adds examples

@paulcsmith paulcsmith force-pushed the pcs/460-readd-helpful-message branch from 0b418b3 to c50cf85 Compare April 5, 2020 02:17
else
redirect Home::Index
end
end
Copy link
Member Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it

Copy link
Member

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
Copy link
Member Author

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

Copy link
Member

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. 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good point!

# 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 %}
Copy link
Member Author

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

Copy link

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.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in perform_action

Copy link
Member Author

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

Copy link
Member Author

@paulcsmith paulcsmith Apr 5, 2020

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

src/lucky/renderable.cr Outdated Show resolved Hide resolved
else
redirect Home::Index
end
end
Copy link
Member

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
Copy link
Member

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. 🙂

Copy link
Member

@jwoertink jwoertink left a 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. 👍

{%
raise <<-ERROR


Your action returned #{T}
#{@type} returned #{T}
Copy link
Member

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? 🤔

Copy link
Member Author

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

For example...

get "/users" do
# Render html, json, or redirect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Render html, json, or redirect
# Return one of html, json, or redirect

Copy link
Member Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same ❤️

Copy link
Member Author

@paulcsmith paulcsmith left a 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!

{%
raise <<-ERROR


Your action returned #{T}
#{@type} returned #{T}
Copy link
Member Author

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 Show resolved Hide resolved
For example...

get "/users" do
# Render html, json, or redirect
Copy link
Member Author

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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good point!

@paulcsmith paulcsmith force-pushed the pcs/460-readd-helpful-message branch 2 times, most recently from 07caa51 to 3f1dc36 Compare April 5, 2020 17:24
@paulcsmith paulcsmith force-pushed the pcs/460-readd-helpful-message branch from 3f1dc36 to 91b736e Compare April 5, 2020 17:25
@paulcsmith paulcsmith merged commit 24613d9 into master Apr 5, 2020
@paulcsmith paulcsmith deleted the pcs/460-readd-helpful-message branch April 5, 2020 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update mention of render -> html
4 participants