-
Couldn't load subscription status.
- Fork 109
Description
Environment details
- OS: MacOs
- Node.js version: v14.4.0
- npm version: 6.14.8
@google-cloud/datastoreversion: 6.3.0
Steps to reproduce
Execute the following code:
async function saveBlob() {
const key = datastore.key(['TEST']);
await datastore.save({
key: key,
data: {
name: 'test',
blob: Buffer.from([])
},
});
}It will trigger an error: Error: 3 INVALID_ARGUMENT: The value "blob" does not contain a value.
I expect to be able to save an empty Buffer without error.
If you change the blob value to Buffer.from([1, 2, 3]) the error disappears.
My use case is that I have a protocol buffer composed of repeated fields only:
message LiveTrack {
optional int64 id = 1 [jstype = JS_NUMBER];
optional string name = 2;
repeated float lat = 3;
repeated float lon = 4;
repeated int32 alt = 5;
repeated int32 time_sec = 6;
repeated uint32 flags = 7;
map<uint32, LiveExtra> extra = 8;
}It could happen that all repeated fields (including the map) are empty. Because the optional field are not populated, the proto would serialize to an empty Buffer.
Workaround
The workaround would be to set the value to null when the Buffer size is 0.
This requires extra code both while saving (to replace the Buffer with null) and while loading (to replace null with the default message).
Other
The wording of the message could be improved: The value "blob" does not contain a value., i.e. use field or key instead of the first "value".