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

serialize maps and lists when passed to echo #994

Merged
merged 1 commit into from
Sep 28, 2016
Merged

Conversation

mpeck
Copy link
Contributor

@mpeck mpeck commented Sep 27, 2016

echo was causing Cog to crash whenever it received a value that didn't implement to_string, ie maps and lists. This change serializes those types with Poison.encode!.

resolves #981

@mpeck mpeck added the review label Sep 27, 2016
defp serialize(list) when is_list(list),
do: Poison.encode!(list)
defp serialize(val),
do: "#{val}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd just call to_string(val) directly, instead of doing an unnecessary string interpolation.

# we might get should implement 'to_string'.
defp serialize(map) when is_map(map),
do: Poison.encode!(map)
defp serialize(list) when is_list(list),
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you change the signature to

serialize(arg) when is_map(arg) or is_list(arg)

you can do it in one function head instead of two. It also makes the explanatory comments above unnecessary, since they are saying exactly what the code is saying.

@christophermaier
Copy link
Collaborator

Also, tests for this new behavior would be good.

Copy link
Collaborator

@christophermaier christophermaier left a comment

Choose a reason for hiding this comment

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

Squash the commits and ship it!

@mpeck mpeck merged commit 3bee79a into master Sep 28, 2016
@mpeck mpeck removed the review label Sep 28, 2016
@mpeck mpeck deleted the peck/echo-serialize branch September 28, 2016 18:29
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.

Echo command crashes with non-string args
2 participants