-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: BSON
-
Not Needed
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Use Case
As a... BSON user / shell user
I want... Binary types to be created in the form they will be serialized in
So that... inspecting them and performing transformations on them do not work with unexpected values
User Experience
- It is desirable that the in memory representation of the Binary object match how it will be serialized as early as possible.
- Match how the Int32 class makes the number truncate to an int32 in the ctor like how it will eventually be truncated in the serializer.
- It sort of leads to bugs:
var uuid = new UUID(); var b = Binary.createFromBase64(u.toString('base64'), '4'); // stringified sub_type! // ... b.toUUID(); BSONError: Binary sub_type "4" is not supported for converting to UUID. Only "4" is currently supported. // hard to tell what this is pointing out // ... BSON.deserialize(BSON.serialize({ b })) // round trips perfectly fine { b: new UUID('1e54853f-d91f-41c7-9f98-f4e6faeec2da') }
Dependencies
- None
Risks/Unknowns
- None
Acceptance Criteria
Implementation Requirements
- In the Binary constructor, match the serializer behavior and cast the subType input to a Number
- Improve the toUUID() error message to make the type information of the subType clear
Testing Requirements
- Regression test for the number casting behavior
- Check for the new improved error message
Documentation Requirements
- TBD? The typescript already claims the property to be a number, the fact that it can be something else seems like we're fixing reality to match the existing docs?
Follow Up Requirements
- Are there other error messages where we stringify the input losing information in the process? (like how the string "4" became indistinguishable from the number "4")