janl commented on issue #927: Confusing error message for bad index creation
URL: https://github.com/apache/couchdb/issues/927#issuecomment-340184977
 
 
   @flimzy good find! Wanna attempt a PR?
   
   Code location is here: 
https://github.com/apache/couchdb/blob/d0445f53a837db374e56eb59ede63694ed6e4c33/src/mango/src/mango_error.erl#L330
   
   What you are seeing is a so-called Erlang binary. In particular, it is a 
three-byte binary with the decimal ascii values of `f`, `o` and `o`.
   
   The problem now is that the format specifier `~w` is meant for [Erlang 
atoms](http://erldocs.com/current/stdlib/io.html?i=0&search=io:format#format/1) 
or roughly an 8-bit ascii string, not a binary.
   
   There are two options now.
   
   1. typecast the binary into a list (that in this case will map to the `~w` 
specifier with 
[`binary_to_list()`](http://erldocs.com/current/erts/erlang.html?i=0&search=binary_to_list#binary_to_list/1)
   
   2. change the format specifier to something that can render the binary into 
the string, namely 
[`~s`](http://erldocs.com/current/stdlib/io.html?i=0&search=io:format#format/1).
   
   One challenge arises, and that?s something you can play with: what if the 
bad sort specifier is not a string, but a JSON structure? Then the above 
solutions would show some different gobbledygook, or they might not. It might 
be worth trying a few different ones and see which solution gets you closest to 
a satisfactory result. If you are looking at solution #2, [check out the other 
format 
specifies](http://erldocs.com/current/stdlib/io.html?i=0&search=io:format#format/1),
 especially `~p`.
   
   Let us know if you have any questions :)
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to