From c2164913e2de5fdcb24b1d5b896eab4bce47a229 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 15 Dec 2017 11:00:05 -0800 Subject: [PATCH 1/5] Add error code name to status error messages --- packages/grpc-native-core/src/client.js | 27 ++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/grpc-native-core/src/client.js b/packages/grpc-native-core/src/client.js index 24af23b8..519b8d79 100644 --- a/packages/grpc-native-core/src/client.js +++ b/packages/grpc-native-core/src/client.js @@ -53,6 +53,21 @@ var Duplex = stream.Duplex; var util = require('util'); var version = require('../package.json').version; +/** + * Create an Error object from a status object + * @private + * @param {grpc~StatusObject} status The status object + * @return {Error} The resulting Error + */ +function createStatusError(status) { + let statusName = _.invert(constants.status)[status.code]; + let message = `${status.code} ${status.name}: ${status.details}`; + let error = new Error(message); + error.code = status.code; + error.details = status.details; + return error; +} + /** * Initial response metadata sent by the server when it starts processing the * call @@ -252,9 +267,7 @@ function _emitStatusIfDone() { if (status.code === constants.status.OK) { this.push(null); } else { - var error = new Error(status.details); - error.code = status.code; - error.metadata = status.metadata; + var error = createStatusError(status); this.emit('error', error); } this.emit('status', status); @@ -551,9 +564,7 @@ Client.prototype.makeUnaryRequest = function(method, serialize, deserialize, } } if (status.code !== constants.status.OK) { - error = new Error(status.details); - error.code = status.code; - error.metadata = status.metadata; + error = new createStatusError(status); args.callback(error); } else { args.callback(null, deserialized); @@ -634,9 +645,7 @@ Client.prototype.makeClientStreamRequest = function(method, serialize, } } if (status.code !== constants.status.OK) { - error = new Error(response.status.details); - error.code = status.code; - error.metadata = status.metadata; + error = createStatusError(status); args.callback(error); } else { args.callback(null, deserialized); From 7edc14bb1a326ea4b31615555a4b8da591d3de64 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 15 Dec 2017 11:35:47 -0800 Subject: [PATCH 2/5] Attach the proper fields to the Error object --- packages/grpc-native-core/src/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/grpc-native-core/src/client.js b/packages/grpc-native-core/src/client.js index 519b8d79..1e873d2c 100644 --- a/packages/grpc-native-core/src/client.js +++ b/packages/grpc-native-core/src/client.js @@ -64,7 +64,7 @@ function createStatusError(status) { let message = `${status.code} ${status.name}: ${status.details}`; let error = new Error(message); error.code = status.code; - error.details = status.details; + error.metadata = status.metadata; return error; } From 264cc4767a41d7306bf57be78d144ff3f29d1ff7 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 10 Jan 2018 14:48:35 -0500 Subject: [PATCH 3/5] Update version and submodule to 1.8.4 --- packages/grpc-native-core/deps/grpc | 2 +- packages/grpc-native-core/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/grpc-native-core/deps/grpc b/packages/grpc-native-core/deps/grpc index ada05afd..77ec6c94 160000 --- a/packages/grpc-native-core/deps/grpc +++ b/packages/grpc-native-core/deps/grpc @@ -1 +1 @@ -Subproject commit ada05afd62a2e5d405bc1ba1c1cf2d775d1a42ea +Subproject commit 77ec6c94ad58bedfdf8f28682914e9893e318be0 diff --git a/packages/grpc-native-core/package.json b/packages/grpc-native-core/package.json index 656ba898..4a6e7307 100644 --- a/packages/grpc-native-core/package.json +++ b/packages/grpc-native-core/package.json @@ -1,6 +1,6 @@ { "name": "grpc", - "version": "1.8.0", + "version": "1.8.4", "author": "Google Inc.", "description": "gRPC Library for Node", "homepage": "https://grpc.io/", From 01d66dd0b5c5be0a4d0230f67142d7d3c13ae5a1 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 12 Jan 2018 15:11:21 -0500 Subject: [PATCH 4/5] Add original details string to errors, update tests --- packages/grpc-native-core/src/client.js | 3 ++- test/api/credentials_test.js | 4 ++-- test/api/surface_test.js | 8 ++++---- test/interop/interop_client.js | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/grpc-native-core/src/client.js b/packages/grpc-native-core/src/client.js index 1e873d2c..389d06b0 100644 --- a/packages/grpc-native-core/src/client.js +++ b/packages/grpc-native-core/src/client.js @@ -61,10 +61,11 @@ var version = require('../package.json').version; */ function createStatusError(status) { let statusName = _.invert(constants.status)[status.code]; - let message = `${status.code} ${status.name}: ${status.details}`; + let message = `${status.code} ${statusName}: ${status.details}`; let error = new Error(message); error.code = status.code; error.metadata = status.metadata; + error.details = status.details; return error; } diff --git a/test/api/credentials_test.js b/test/api/credentials_test.js index e05ec764..17189267 100644 --- a/test/api/credentials_test.js +++ b/test/api/credentials_test.js @@ -319,7 +319,7 @@ describe('client credentials', function() { client_options); client.unary({}, function(err, data) { assert(err); - assert.strictEqual(err.message, + assert.strictEqual(err.details, 'Getting metadata from plugin failed with error: ' + 'Authentication error'); assert.strictEqual(err.code, grpc.status.UNAUTHENTICATED); @@ -369,7 +369,7 @@ describe('client credentials', function() { client_options); client.unary({}, function(err, data) { assert(err); - assert.strictEqual(err.message, + assert.strictEqual(err.details, 'Getting metadata from plugin failed with error: ' + 'Authentication failure'); done(); diff --git a/test/api/surface_test.js b/test/api/surface_test.js index 5fdcbcfb..3bffaf8e 100644 --- a/test/api/surface_test.js +++ b/test/api/surface_test.js @@ -981,7 +981,7 @@ describe('Other conditions', function() { client.unary({error: true}, function(err, data) { assert(err); assert.strictEqual(err.code, grpc.status.UNKNOWN); - assert.strictEqual(err.message, 'Requested error'); + assert.strictEqual(err.details, 'Requested error'); done(); }); }); @@ -989,7 +989,7 @@ describe('Other conditions', function() { var call = client.clientStream(function(err, data) { assert(err); assert.strictEqual(err.code, grpc.status.UNKNOWN); - assert.strictEqual(err.message, 'Requested error'); + assert.strictEqual(err.details, 'Requested error'); done(); }); call.write({error: false}); @@ -1001,7 +1001,7 @@ describe('Other conditions', function() { call.on('data', function(){}); call.on('error', function(error) { assert.strictEqual(error.code, grpc.status.UNKNOWN); - assert.strictEqual(error.message, 'Requested error'); + assert.strictEqual(error.details, 'Requested error'); done(); }); }); @@ -1013,7 +1013,7 @@ describe('Other conditions', function() { call.on('data', function(){}); call.on('error', function(error) { assert.strictEqual(error.code, grpc.status.UNKNOWN); - assert.strictEqual(error.message, 'Requested error'); + assert.strictEqual(error.details, 'Requested error'); done(); }); }); diff --git a/test/interop/interop_client.js b/test/interop/interop_client.js index 73b84c38..83890bca 100644 --- a/test/interop/interop_client.js +++ b/test/interop/interop_client.js @@ -347,7 +347,7 @@ function statusCodeAndMessage(client, done) { client.unaryCall(arg, function(err, resp) { assert(err); assert.strictEqual(err.code, 2); - assert.strictEqual(err.message, 'test status message'); + assert.strictEqual(err.details, 'test status message'); done(); }); var duplex = client.fullDuplexCall(); From e3c3c3462f98d6e7903e2f282de184609f33ca44 Mon Sep 17 00:00:00 2001 From: Kelvin Jin Date: Wed, 31 Jan 2018 14:28:39 -0800 Subject: [PATCH 5/5] Fix TS compiler errors and pin TS to 2.7 --- package.json | 2 +- packages/grpc-js-core/package.json | 2 +- packages/grpc-js-core/src/channel.ts | 4 ++-- packages/grpc-js-core/test/test-call-stream.ts | 10 +++++----- packages/grpc-js-core/test/test-channel-credentials.ts | 2 +- packages/grpc-js/package.json | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index cb324a08..5310e7f5 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "through2": "^2.0.3", "ts-node": "^3.3.0", "tslint": "^5.5.0", - "typescript": "^2.5.1", + "typescript": "~2.7.0", "xml2js": "^0.4.19" }, "contributors": [ diff --git a/packages/grpc-js-core/package.json b/packages/grpc-js-core/package.json index d5fdd46c..e0d48bd4 100644 --- a/packages/grpc-js-core/package.json +++ b/packages/grpc-js-core/package.json @@ -19,7 +19,7 @@ "@types/node": "^8.0.55", "clang-format": "^1.0.55", "gts": "^0.5.1", - "typescript": "^2.6.1" + "typescript": "~2.7.0" }, "contributors": [ { diff --git a/packages/grpc-js-core/src/channel.ts b/packages/grpc-js-core/src/channel.ts index 35ca6f6c..51ec1fa5 100644 --- a/packages/grpc-js-core/src/channel.ts +++ b/packages/grpc-js-core/src/channel.ts @@ -76,7 +76,7 @@ export class Http2Channel extends EventEmitter implements Channel { private connectivityState: ConnectivityState = ConnectivityState.IDLE; /* For now, we have up to one subchannel, which will exist as long as we are * connecting or trying to connect */ - private subChannel: http2.ClientHttp2Session|null; + private subChannel: http2.ClientHttp2Session|null = null; private filterStackFactory: FilterStackFactory; private subChannelConnectCallback: ()=>void = () => {}; @@ -123,7 +123,7 @@ export class Http2Channel extends EventEmitter implements Channel { } // Transition from any of a set of oldStates to a specific newState - private transitionToState(oldStates: [ConnectivityState], newState: ConnectivityState): void { + private transitionToState(oldStates: ConnectivityState[], newState: ConnectivityState): void { if (oldStates.indexOf(this.connectivityState) > -1) { let oldState: ConnectivityState = this.connectivityState; this.connectivityState = newState; diff --git a/packages/grpc-js-core/test/test-call-stream.ts b/packages/grpc-js-core/test/test-call-stream.ts index e7126d62..91d694dc 100644 --- a/packages/grpc-js-core/test/test-call-stream.ts +++ b/packages/grpc-js-core/test/test-call-stream.ts @@ -38,11 +38,11 @@ class ClientHttp2StreamMock extends stream.Duplex implements http2.ClientHttp2St } bytesRead = 0; dataFrame = 0; - aborted: boolean; - destroyed: boolean; - rstCode: number; - session: http2.Http2Session; - state: http2.StreamState; + aborted: boolean = false; + destroyed: boolean = false; + rstCode: number = 0; + session: http2.Http2Session = {} as any; + state: http2.StreamState = {} as any; priority = mockFunction; rstStream = mockFunction; rstWithNoError = mockFunction; diff --git a/packages/grpc-js-core/test/test-channel-credentials.ts b/packages/grpc-js-core/test/test-channel-credentials.ts index fac88110..15dfbfac 100644 --- a/packages/grpc-js-core/test/test-channel-credentials.ts +++ b/packages/grpc-js-core/test/test-channel-credentials.ts @@ -8,7 +8,7 @@ import {ChannelCredentials} from '../src/channel-credentials'; import {assert2, mockFunction} from './common'; class CallCredentialsMock implements CallCredentials { - child: CallCredentialsMock; + child: CallCredentialsMock|null = null; constructor(child?: CallCredentialsMock) { if (child) { this.child = child; diff --git a/packages/grpc-js/package.json b/packages/grpc-js/package.json index 1dbddbb0..8486c043 100644 --- a/packages/grpc-js/package.json +++ b/packages/grpc-js/package.json @@ -29,6 +29,6 @@ }, "devDependencies": { "gts": "^0.5.1", - "typescript": "^2.6.1" + "typescript": "~2.7.0" } }