-
Type: Improvement
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
In Ruby we have the #to_bson method on various classes that implements serialization to bson. Depending on what type of object it's called on, it produces either complete legal bson documents or document fragments.
libmongocrypt as I understand it requires complete legal bson documents as input. Therefore code like the following is problematic:
data = command.to_bson.to_s Binary.wrap_string(data) do |data_p| check_ctx_status(context) do mongocrypt_ctx_encrypt_init(context.ctx_p, db_name, an_int, data_p) end end
If command is nil (or of a wrong type like Integer), it's still possible to call to_bson on it which produces a partial bson fragment, which eventually produces a not very descriptive error in libmongocrypt per https://jira.mongodb.org/browse/MONGOCRYPT-246.
To improve diagnostics in Ruby driver we should take steps to ensure that the data we give to libmongocrypt is complete bson documents. I believe checking that the type of objects that #to_bson is called on, and requiring that those are Hash instances, would be sufficient to start.
- related to
-
MONGOCRYPT-246 Provide descriptive error message instead of "BSON malformed"
- Backlog