Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
BSON::Binary error when data is non-utf8 compatible string
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
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
You can’t perform that action at this time.