Skip to content

Commit

Permalink
fix: reject all promises with errors (#1224)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Chen committed Jun 17, 2020
1 parent 6681ef7 commit 9118521
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
4 changes: 3 additions & 1 deletion dev/src/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ export class ClientPool<T> {
*/
run<V>(requestTag: string, op: (client: T) => Promise<V>): Promise<V> {
if (this.terminated) {
return Promise.reject('The client has already been terminated');
return Promise.reject(
new Error('The client has already been terminated')
);
}
const client = this.acquire(requestTag);

Expand Down
7 changes: 1 addition & 6 deletions dev/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,7 @@ export function getRetryParams(methodName: string): BackoffSettings {
* Used to preserve stack traces across async calls.
* @private
*/
export function wrapError(err: Error | string, stack: string): Error {
// TODO(b/157506412): Remove `string` type and clean up any string errors
// that we are throwing.
if (typeof err === 'string') {
throw err;
}
export function wrapError(err: Error, stack: string): Error {
err.stack += '\nCaused by: ' + stack;
return err;
}
4 changes: 3 additions & 1 deletion dev/src/v1/firestore_admin_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ export class FirestoreAdminClient {
const innerCallPromise = this.firestoreAdminStub.then(
stub => (...args: Array<{}>) => {
if (this._terminated) {
return Promise.reject('The client has already been closed.');
return Promise.reject(
new Error('The client has already been closed.')
);
}
const func = stub[methodName];
return func.apply(stub, args);
Expand Down
4 changes: 3 additions & 1 deletion dev/src/v1/firestore_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ export class FirestoreClient {
const innerCallPromise = this.firestoreStub.then(
stub => (...args: Array<{}>) => {
if (this._terminated) {
return Promise.reject('The client has already been closed.');
return Promise.reject(
new Error('The client has already been closed.')
);
}
const func = stub[methodName];
return func.apply(stub, args);
Expand Down
4 changes: 3 additions & 1 deletion dev/src/v1beta1/firestore_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ export class FirestoreClient {
const innerCallPromise = this.firestoreStub.then(
stub => (...args: Array<{}>) => {
if (this._terminated) {
return Promise.reject('The client has already been closed.');
return Promise.reject(
new Error('The client has already been closed.')
);
}
const func = stub[methodName];
return func.apply(stub, args);
Expand Down
2 changes: 1 addition & 1 deletion dev/system-test/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('Firestore class', () => {
})
.then(() => Promise.reject('set() should have failed'))
.catch(err => {
expect(err).to.equal('The client has already been terminated');
expect(err.message).to.equal('The client has already been terminated');
});
});

Expand Down
2 changes: 1 addition & 1 deletion dev/test/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ describe('Client pool', () => {
);
})
.catch((err: Error) => {
expect(err).to.equal('The client has already been terminated');
expect(err.message).to.equal('The client has already been terminated');
});
});

Expand Down

0 comments on commit 9118521

Please sign in to comment.