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

Avoid misleading error message in HTTP::Params.encode #5184

Merged
merged 1 commit into from Oct 26, 2017
Merged

Avoid misleading error message in HTTP::Params.encode #5184

merged 1 commit into from Oct 26, 2017

Conversation

luislavena
Copy link
Contributor

Restrict types supported by HTTP::Params.encode to avoid long and confusing error messages.

With this change, attempt to use a Hash other than Hash(String, String) will result in a better error message:

require "http/params"

puts HTTP::Params.encode({"foo" => 10})

Output:

no overload matches 'HTTP::Params.encode' with type Hash(String, Int32)
Overloads are:
 - HTTP::Params.encode(hash : Hash(String, String))
 - HTTP::Params.encode(named_tuple : NamedTuple)

Also includes examples on usage.

Fixes #5172

Thank you.
❤️ ❤️ ❤️

Restrict types supported by HTTP::Params.encode to avoid long and confusing
error messages.

With this change, attempt to use a `Hash` other than `Hash(String, String)`
will result in a better error message:

    require "http/params"

    puts HTTP::Params.encode({"foo" => 10})

Output:

    no overload matches 'HTTP::Params.encode' with type Hash(String, Int32)
    Overloads are:
     - HTTP::Params.encode(hash : Hash(String, String))
     - HTTP::Params.encode(named_tuple : NamedTuple)

Also includes examples on usage.

Fixes #5172
Copy link
Member

@asterite asterite left a comment

Choose a reason for hiding this comment

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

Cool, thank you!

@asterite asterite added this to the Next milestone Oct 26, 2017
@asterite asterite merged commit 4e079f9 into crystal-lang:master Oct 26, 2017
@luislavena luislavena deleted the restrict-type-on-http-params-encode branch October 26, 2017 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants