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

Provide helpful error when dashes are used in path variables #1238

Merged

Conversation

matthewmcgarvey
Copy link
Member

Purpose

The error message given when using a dash in a path variable is unhelpful to solving the issue. Changing the message allows users to fix the issue.

Fixes #1235

Description

Before

There was a problem expanding macro 'add_route'

Code in macro 'match'

 5 | add_route(:get, "/test/:param-1/:param_2", TestParamAction)
     ^
Called macro defined in src/lucky/routable.cr:191:3

 191 | macro add_route(method, path, action)

Which expanded to:

 >  7 |     
 >  8 |       
 >  9 |       def param-1 : String
                      ^
Error: unexpected token: -1

After

Showing last frame. Use --error-trace for full trace.

There was a problem expanding macro 'get'

Code in spec/lucky/action_route_params_spec.cr:6:3

 6 | get "/test/:param-1/:param_2" do
     ^
Called macro defined in macro 'macro_4475664912'

 19 | macro get(path)

Which expanded to:

 > 1 | match(:get, "/test/:param-1/:param_2") do
       ^
Error: Path variables must only use underscores. Use ":param_1" instead of ":param-1".

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

👍

Copy link
Member

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

Looks great. Thanks @matthewmcgarvey!

@paulcsmith paulcsmith merged commit 417eac8 into luckyframework:master Aug 19, 2020
@matthewmcgarvey matthewmcgarvey deleted the path-variable-dashes branch August 19, 2020 03:27
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.

Attempting to use dashes in path variable naming produces unhelpful error
3 participants