mirror of https://github.com/grpc/grpc-node.git
Node: correctly bubble up errors caused by non-serializable writes
This commit is contained in:
parent
ead0505db5
commit
d0402e0093
|
@ -99,7 +99,18 @@ function ClientWritableStream(call, serialize) {
|
||||||
function _write(chunk, encoding, callback) {
|
function _write(chunk, encoding, callback) {
|
||||||
/* jshint validthis: true */
|
/* jshint validthis: true */
|
||||||
var batch = {};
|
var batch = {};
|
||||||
var message = this.serialize(chunk);
|
var message;
|
||||||
|
try {
|
||||||
|
message = this.serialize(chunk);
|
||||||
|
} catch (e) {
|
||||||
|
/* Sending this error to the server and emitting it immediately on the
|
||||||
|
client may put the call in a slightly weird state on the client side,
|
||||||
|
but passing an object that causes a serialization failure is a misuse
|
||||||
|
of the API anyway, so that's OK. The primary purpose here is to give the
|
||||||
|
programmer a useful error and to stop the stream properly */
|
||||||
|
this.call.cancelWithStatus(grpc.status.INTERNAL, "Serialization failure");
|
||||||
|
callback(e);
|
||||||
|
}
|
||||||
if (_.isFinite(encoding)) {
|
if (_.isFinite(encoding)) {
|
||||||
/* Attach the encoding if it is a finite number. This is the closest we
|
/* Attach the encoding if it is a finite number. This is the closest we
|
||||||
* can get to checking that it is valid flags */
|
* can get to checking that it is valid flags */
|
||||||
|
|
|
@ -278,7 +278,12 @@ function _write(chunk, encoding, callback) {
|
||||||
(new Metadata())._getCoreRepresentation();
|
(new Metadata())._getCoreRepresentation();
|
||||||
this.call.metadataSent = true;
|
this.call.metadataSent = true;
|
||||||
}
|
}
|
||||||
var message = this.serialize(chunk);
|
var message;
|
||||||
|
try {
|
||||||
|
message = this.serialize(chunk);
|
||||||
|
} catch (e) {
|
||||||
|
callback(e);
|
||||||
|
}
|
||||||
if (_.isFinite(encoding)) {
|
if (_.isFinite(encoding)) {
|
||||||
/* Attach the encoding if it is a finite number. This is the closest we
|
/* Attach the encoding if it is a finite number. This is the closest we
|
||||||
* can get to checking that it is valid flags */
|
* can get to checking that it is valid flags */
|
||||||
|
|
Loading…
Reference in New Issue