From 65b784e230e93a4335a8e8708cc2ae8cd5583de1 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 6 May 2015 16:46:19 -0700 Subject: [PATCH 1/2] Added error events on client streams when the server is streaming --- src/node/interop/interop_client.js | 4 ++-- src/node/src/client.js | 16 ++++++++++++++++ src/node/test/math_client_test.js | 3 +-- src/node/test/surface_test.js | 18 ++++++++---------- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/node/interop/interop_client.js b/src/node/interop/interop_client.js index 3341486b9ed..02f341113d3 100644 --- a/src/node/interop/interop_client.js +++ b/src/node/interop/interop_client.js @@ -260,8 +260,8 @@ function cancelAfterFirstResponse(client, done) { call.on('data', function(data) { call.cancel(); }); - call.on('status', function(status) { - assert.strictEqual(status.code, grpc.status.CANCELLED); + call.on('error', function(error) { + assert.strictEqual(error.code, grpc.status.CANCELLED); done(); }); } diff --git a/src/node/src/client.js b/src/node/src/client.js index fad369c2f80..cd59a0673af 100644 --- a/src/node/src/client.js +++ b/src/node/src/client.js @@ -245,6 +245,7 @@ function makeUnaryRequestFunction(method, serialize, deserialize) { if (response.status.code !== grpc.status.OK) { var error = new Error(response.status.details); error.code = response.status.code; + error.metadata = response.status.metadata; callback(error); return; } @@ -316,6 +317,7 @@ function makeClientStreamRequestFunction(method, serialize, deserialize) { if (response.status.code !== grpc.status.OK) { var error = new Error(response.status.details); error.code = response.status.code; + error.metadata = response.status.metadata; callback(error); return; } @@ -382,6 +384,13 @@ function makeServerStreamRequestFunction(method, serialize, deserialize) { throw err; } stream.emit('status', response.status); + if (response.status.code !== grpc.status.OK) { + var error = new Error(response.status.details); + error.code = response.status.code; + error.metadata = response.status.metadata; + stream.emit('error', error); + return; + } }); }); return stream; @@ -440,6 +449,13 @@ function makeBidiStreamRequestFunction(method, serialize, deserialize) { throw err; } stream.emit('status', response.status); + if (response.status.code !== grpc.status.OK) { + var error = new Error(response.status.details); + error.code = response.status.code; + error.metadata = response.status.metadata; + stream.emit('error', error); + return; + } }); }); return stream; diff --git a/src/node/test/math_client_test.js b/src/node/test/math_client_test.js index 79df97871bf..3461922e662 100644 --- a/src/node/test/math_client_test.js +++ b/src/node/test/math_client_test.js @@ -130,8 +130,7 @@ describe('Math client', function() { }); call.write({dividend: 7, divisor: 0}); call.end(); - call.on('status', function checkStatus(status) { - assert.notEqual(status.code, grpc.status.OK); + call.on('error', function checkStatus(status) { done(); }); }); diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js index 6f63f1044fa..38f9028bffb 100644 --- a/src/node/test/surface_test.js +++ b/src/node/test/surface_test.js @@ -278,9 +278,8 @@ describe('Trailing metadata', function() { it('should be present when a server stream call fails', function(done) { var call = client.serverStream({error: true}); call.on('data', function(){}); - call.on('status', function(status) { - assert.notStrictEqual(status.code, grpc.status.OK); - assert.deepEqual(status.metadata.metadata, ['yes']); + call.on('error', function(error) { + assert.deepEqual(error.metadata.metadata, ['yes']); done(); }); }); @@ -302,9 +301,8 @@ describe('Trailing metadata', function() { call.write({error: true}); call.end(); call.on('data', function(){}); - call.on('status', function(status) { - assert.notStrictEqual(status.code, grpc.status.OK); - assert.deepEqual(status.metadata.metadata, ['yes']); + call.on('error', function(error) { + assert.deepEqual(error.metadata.metadata, ['yes']); done(); }); }); @@ -345,16 +343,16 @@ describe('Cancelling surface client', function() { }); it('Should correctly cancel a server stream call', function(done) { var call = client.fib({'limit': 5}); - call.on('status', function(status) { - assert.strictEqual(status.code, surface_client.status.CANCELLED); + call.on('error', function(error) { + assert.strictEqual(error.code, surface_client.status.CANCELLED); done(); }); call.cancel(); }); it('Should correctly cancel a bidi stream call', function(done) { var call = client.divMany(); - call.on('status', function(status) { - assert.strictEqual(status.code, surface_client.status.CANCELLED); + call.on('error', function(error) { + assert.strictEqual(error.code, surface_client.status.CANCELLED); done(); }); call.cancel(); From f742c52d9d09f6688ddf8ca4f3be0bd5acc39887 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 6 May 2015 17:00:17 -0700 Subject: [PATCH 2/2] Version bump because of new exposed errors --- src/node/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/package.json b/src/node/package.json index 6c0953a83f2..0bb3c3d1fd0 100644 --- a/src/node/package.json +++ b/src/node/package.json @@ -1,6 +1,6 @@ { "name": "grpc", - "version": "0.6.2", + "version": "0.7.0", "author": "Google Inc.", "description": "gRPC Library for Node", "homepage": "http://www.grpc.io/",