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

Better error when using route helpers incorrectly #1372

Conversation

matthewmcgarvey
Copy link
Member

@matthewmcgarvey matthewmcgarvey commented Dec 28, 2020

Purpose

Fixes #1005

Description

There's an implementation Lucky::Routable.route that handles correct usage but when the method is called incorrectly it provides a confusing error message. We're seeing people assume it was a problem in their action and not where the error actually is, where they try to create a link or something using the action class name.

Before

CleanShot 2020-12-28 at 12 29 40@2x

After

CleanShot 2020-12-28 at 16 47 25@2x

I'm still kind of disappointed with the error message. I was hoping that by adding the compilation error it would point towards the usage site but it still doesn't.

Checklist

  • - An issue already exists detailing the issue/or feature request that this PR fixes
  • - All specs are formatted with crystal tool format spec src
  • - Inline documentation has been added and/or updated
  • - Lucky builds on docker with ./script/setup
  • - All builds and specs pass on docker with ./script/test

Copy link
Contributor

@robacarp robacarp left a comment

Choose a reason for hiding this comment

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

This is a big area of confusion for me, and rendering an error which is more helpful than Crystal will help a ton. For me it goes like this:

  • Edit the need of an action (ohh how easy it is to just add a need! just so easy! spill the bucket of red paint on the floor)
  • Edit "the page that uses the action"
  • See this opaque error
  • Open up terminal and start grepping for other uses of the ActionName
  • Clean up the mess with a mop until the floor is clean enough to compile again

src/lucky/routable.cr Outdated Show resolved Hide resolved
{% end %}{% if !optionals.empty? %}
Optional arguments:
{% for opts in optionals %}\n- {{ opts.id }}{% end %}
{% end %}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this list be formatted more like a method call, or terminal documentation?

A stab in the dark: {{ @type }}.with( {{ required things }}, [ {{ optional things }} ] ) or something? It's confusing to me to see the arguments broken out in a bulleted list like this.

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 looked into doing something like this but I'd be afraid that if I put that in the error message that it would be an indication of the correct way to call it but the [ {{ optional }} ] part is not right.

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.

Just a few comments.

src/lucky/routable.cr Outdated Show resolved Hide resolved
src/lucky/routable.cr Outdated Show resolved Hide resolved
src/lucky/routable.cr Show resolved Hide resolved
src/lucky/routable.cr Show resolved Hide resolved
@matthewmcgarvey matthewmcgarvey force-pushed the matthewmcgarvey/issue1005 branch from 6a6ccf3 to 97d065b Compare December 28, 2020 21:49
Copy link
Contributor

@robacarp robacarp left a comment

Choose a reason for hiding this comment

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

this will save me buckets of time, thanks @matthewmcgarvey

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.

👍

@matthewmcgarvey matthewmcgarvey merged commit f60a16d into luckyframework:master Dec 31, 2020
@matthewmcgarvey matthewmcgarvey deleted the matthewmcgarvey/issue1005 branch December 31, 2020 23:30
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.

Better error when passing incorrect number of params to routes
3 participants