Created
July 11, 2015 19:52
-
-
Save amw/96b791e6c134a419528f to your computer and use it in GitHub Desktop.
BSON::Binary error when data is non-utf8 compatible string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "bson" | |
require "digest/sha2" | |
d = Digest::SHA256.new | |
d << "test" | |
string = d.digest | |
puts string.encoding | |
binary = BSON::Binary.new string | |
puts binary.to_bson |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mongoid-errors$ruby binary-encoding.rb | |
ASCII-8BIT | |
/usr/local/lib/ruby/gems/2.2.0/gems/bson-3.1.2/lib/bson/binary.rb:137:in `encode': "\x9F" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError) | |
from /usr/local/lib/ruby/gems/2.2.0/gems/bson-3.1.2/lib/bson/binary.rb:137:in `block in to_bson' | |
from /usr/local/lib/ruby/gems/2.2.0/gems/bson-3.1.2/lib/bson/encodable.rb:81:in `encode_binary_data_with_placeholder' | |
from /usr/local/lib/ruby/gems/2.2.0/gems/bson-3.1.2/lib/bson/binary.rb:134:in `to_bson' | |
from binary-encoding.rb:9:in `<main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment