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

don't blow up if passed an unexpected value #22

Merged
merged 2 commits into from
May 3, 2020

Conversation

rubysolo
Copy link
Contributor

@rubysolo rubysolo commented May 1, 2020

After upgrading to Phoenix 1.5 and enabling the live dashboard, I started seeing no function clause matching errors when the StringFormatter received a tuple. This PR adds a safe fallback if the value passed in is not an expected shape.

@pmenhart
Copy link

pmenhart commented May 1, 2020

Just my personal preference: I'd like to see "#{inspect value}" in my logs, instead of "(unprintable)".

Also note that there is yet another open gap: defp format_value(value) when is_map(value) fails if the map contains values that are not parseable by Jason.

@rubysolo
Copy link
Contributor Author

rubysolo commented May 1, 2020

That makes sense -- I was originally thinking that some values might not be inspectable, or some inspected values might be quite large (e.g. a Plug.Conn), but that's probably being too paranoid.

Good point about unserializable maps, but I'm not sure there's a great generic solution -- I think you would have to iterate over the map looking for key/value patterns to reject, deal with (potentially deeply) nested maps, etc.

@pmenhart
Copy link

pmenhart commented May 1, 2020

If size of inspected values is a concern, then Inspect.Opts can help.

Each project may have different expectations. I usually end up with custom formatters. Typically I rescue errors and use inspect as a last resort - that solves issues like the unserializable map problem. (Then I check logs for such issues - a permanent remedy could be implementing Jason.Encoder for some internal structs.)

@navinpeiris navinpeiris merged commit 2d24779 into navinpeiris:master May 3, 2020
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.

3 participants