Skip to content

Commit 7fa0bd6

Browse files
authored
Merge pull request #166 from grpc/master
Merge master into v1.9.x
2 parents 5e07d60 + 5017667 commit 7fa0bd6

File tree

10 files changed

+37
-27
lines changed

10 files changed

+37
-27
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"through2": "^2.0.3",
3939
"ts-node": "^3.3.0",
4040
"tslint": "^5.5.0",
41-
"typescript": "^2.5.1",
41+
"typescript": "~2.7.0",
4242
"xml2js": "^0.4.19"
4343
},
4444
"contributors": [

packages/grpc-js-core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@types/node": "^8.0.55",
2020
"clang-format": "^1.0.55",
2121
"gts": "^0.5.1",
22-
"typescript": "^2.6.1"
22+
"typescript": "~2.7.0"
2323
},
2424
"contributors": [
2525
{

packages/grpc-js-core/src/channel.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class Http2Channel extends EventEmitter implements Channel {
7676
private connectivityState: ConnectivityState = ConnectivityState.IDLE;
7777
/* For now, we have up to one subchannel, which will exist as long as we are
7878
* connecting or trying to connect */
79-
private subChannel: http2.ClientHttp2Session|null;
79+
private subChannel: http2.ClientHttp2Session|null = null;
8080
private filterStackFactory: FilterStackFactory;
8181

8282
private subChannelConnectCallback: ()=>void = () => {};
@@ -123,7 +123,7 @@ export class Http2Channel extends EventEmitter implements Channel {
123123
}
124124

125125
// Transition from any of a set of oldStates to a specific newState
126-
private transitionToState(oldStates: [ConnectivityState], newState: ConnectivityState): void {
126+
private transitionToState(oldStates: ConnectivityState[], newState: ConnectivityState): void {
127127
if (oldStates.indexOf(this.connectivityState) > -1) {
128128
let oldState: ConnectivityState = this.connectivityState;
129129
this.connectivityState = newState;

packages/grpc-js-core/test/test-call-stream.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ class ClientHttp2StreamMock extends stream.Duplex implements http2.ClientHttp2St
3838
}
3939
bytesRead = 0;
4040
dataFrame = 0;
41-
aborted: boolean;
42-
destroyed: boolean;
43-
rstCode: number;
44-
session: http2.Http2Session;
45-
state: http2.StreamState;
41+
aborted: boolean = false;
42+
destroyed: boolean = false;
43+
rstCode: number = 0;
44+
session: http2.Http2Session = {} as any;
45+
state: http2.StreamState = {} as any;
4646
priority = mockFunction;
4747
rstStream = mockFunction;
4848
rstWithNoError = mockFunction;

packages/grpc-js-core/test/test-channel-credentials.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {ChannelCredentials} from '../src/channel-credentials';
88
import {assert2, mockFunction} from './common';
99

1010
class CallCredentialsMock implements CallCredentials {
11-
child: CallCredentialsMock;
11+
child: CallCredentialsMock|null = null;
1212
constructor(child?: CallCredentialsMock) {
1313
if (child) {
1414
this.child = child;

packages/grpc-js/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
},
3030
"devDependencies": {
3131
"gts": "^0.5.1",
32-
"typescript": "^2.6.1"
32+
"typescript": "~2.7.0"
3333
}
3434
}

packages/grpc-native-core/src/client.js

+19-9
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ var Duplex = stream.Duplex;
5252
var util = require('util');
5353
var version = require('../package.json').version;
5454

55+
/**
56+
* Create an Error object from a status object
57+
* @private
58+
* @param {grpc~StatusObject} status The status object
59+
* @return {Error} The resulting Error
60+
*/
61+
function createStatusError(status) {
62+
let statusName = _.invert(constants.status)[status.code];
63+
let message = `${status.code} ${statusName}: ${status.details}`;
64+
let error = new Error(message);
65+
error.code = status.code;
66+
error.metadata = status.metadata;
67+
error.details = status.details;
68+
return error;
69+
}
70+
5571
/**
5672
* Initial response metadata sent by the server when it starts processing the
5773
* call
@@ -251,9 +267,7 @@ function _emitStatusIfDone() {
251267
if (status.code === constants.status.OK) {
252268
this.push(null);
253269
} else {
254-
var error = new Error(status.details);
255-
error.code = status.code;
256-
error.metadata = status.metadata;
270+
var error = createStatusError(status);
257271
this.emit('error', error);
258272
}
259273
this.emit('status', status);
@@ -556,9 +570,7 @@ Client.prototype.makeUnaryRequest = function(method, serialize, deserialize,
556570
}
557571
}
558572
if (status.code !== constants.status.OK) {
559-
error = new Error(status.details);
560-
error.code = status.code;
561-
error.metadata = status.metadata;
573+
error = new createStatusError(status);
562574
callback(error);
563575
} else {
564576
callback(null, deserialized);
@@ -645,9 +657,7 @@ Client.prototype.makeClientStreamRequest = function(method, serialize,
645657
}
646658
}
647659
if (status.code !== constants.status.OK) {
648-
error = new Error(response.status.details);
649-
error.code = status.code;
650-
error.metadata = status.metadata;
660+
error = createStatusError(status);
651661
callback(error);
652662
} else {
653663
callback(null, deserialized);

test/api/credentials_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ describe('client credentials', function() {
319319
client_options);
320320
client.unary({}, function(err, data) {
321321
assert(err);
322-
assert.strictEqual(err.message,
322+
assert.strictEqual(err.details,
323323
'Getting metadata from plugin failed with error: ' +
324324
'Authentication error');
325325
assert.notStrictEqual(err.code, grpc.status.OK);
@@ -369,7 +369,7 @@ describe('client credentials', function() {
369369
client_options);
370370
client.unary({}, function(err, data) {
371371
assert(err);
372-
assert.strictEqual(err.message,
372+
assert.strictEqual(err.details,
373373
'Getting metadata from plugin failed with error: ' +
374374
'Authentication failure');
375375
done();

test/api/surface_test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -981,15 +981,15 @@ describe('Other conditions', function() {
981981
client.unary({error: true}, function(err, data) {
982982
assert(err);
983983
assert.strictEqual(err.code, grpc.status.UNKNOWN);
984-
assert.strictEqual(err.message, 'Requested error');
984+
assert.strictEqual(err.details, 'Requested error');
985985
done();
986986
});
987987
});
988988
it('for a client stream call', function(done) {
989989
var call = client.clientStream(function(err, data) {
990990
assert(err);
991991
assert.strictEqual(err.code, grpc.status.UNKNOWN);
992-
assert.strictEqual(err.message, 'Requested error');
992+
assert.strictEqual(err.details, 'Requested error');
993993
done();
994994
});
995995
call.write({error: false});
@@ -1001,7 +1001,7 @@ describe('Other conditions', function() {
10011001
call.on('data', function(){});
10021002
call.on('error', function(error) {
10031003
assert.strictEqual(error.code, grpc.status.UNKNOWN);
1004-
assert.strictEqual(error.message, 'Requested error');
1004+
assert.strictEqual(error.details, 'Requested error');
10051005
done();
10061006
});
10071007
});
@@ -1013,7 +1013,7 @@ describe('Other conditions', function() {
10131013
call.on('data', function(){});
10141014
call.on('error', function(error) {
10151015
assert.strictEqual(error.code, grpc.status.UNKNOWN);
1016-
assert.strictEqual(error.message, 'Requested error');
1016+
assert.strictEqual(error.details, 'Requested error');
10171017
done();
10181018
});
10191019
});

test/interop/interop_client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ function statusCodeAndMessage(client, done) {
347347
client.unaryCall(arg, function(err, resp) {
348348
assert(err);
349349
assert.strictEqual(err.code, 2);
350-
assert.strictEqual(err.message, 'test status message');
350+
assert.strictEqual(err.details, 'test status message');
351351
done();
352352
});
353353
var duplex = client.fullDuplexCall();

0 commit comments

Comments
 (0)