From 541449ab15333f8ea0975b2368ae8d3a0705deb6 Mon Sep 17 00:00:00 2001 From: Brian Chen Date: Thu, 21 May 2020 16:04:32 -0700 Subject: [PATCH] add comments + test --- dev/src/bulk-writer.ts | 4 ++-- dev/src/index.ts | 4 ++-- dev/src/pool.ts | 2 +- dev/src/reference.ts | 4 ++-- dev/src/util.ts | 2 +- dev/src/write-batch.ts | 5 ++--- dev/system-test/firestore.ts | 11 +++++++++++ 7 files changed, 21 insertions(+), 11 deletions(-) diff --git a/dev/src/bulk-writer.ts b/dev/src/bulk-writer.ts index 0817e76e1..02bd6619f 100644 --- a/dev/src/bulk-writer.ts +++ b/dev/src/bulk-writer.ts @@ -190,10 +190,10 @@ class BulkCommitBatch { this.state = BatchState.SENT; // Capture the error stack to preserve stack tracing across async calls. - const stack = Error().stack; + const stack = Error().stack!; return this.writeBatch.bulkCommit().catch(err => { - throw wrapError(err, stack!); + throw wrapError(err, stack); }); } diff --git a/dev/src/index.ts b/dev/src/index.ts index 871c63839..1698a2119 100644 --- a/dev/src/index.ts +++ b/dev/src/index.ts @@ -910,12 +910,12 @@ export class Firestore { const tag = requestTag(); // Capture the error stack to preserve stack tracing across async calls. - const stack = Error().stack; + const stack = Error().stack!; return this.initializeIfNeeded(tag).then(() => this.getAll_(documents, fieldMask, tag) ).catch(err => { - throw wrapError(err, stack!); + throw wrapError(err, stack); }); } diff --git a/dev/src/pool.ts b/dev/src/pool.ts index 51c4034f5..eb55c9f90 100644 --- a/dev/src/pool.ts +++ b/dev/src/pool.ts @@ -17,7 +17,7 @@ import * as assert from 'assert'; import {logger} from './logger'; -import {Deferred, wrapError} from './util'; +import {Deferred} from './util'; /** * An auto-resizing pool that distributes concurrent operations over multiple diff --git a/dev/src/reference.ts b/dev/src/reference.ts index 2d6e05a7d..690e1f794 100644 --- a/dev/src/reference.ts +++ b/dev/src/reference.ts @@ -1809,14 +1809,14 @@ export class Query { const docs: Array> = []; // Capture the error stack to preserve stack tracing across async calls. - const stack = Error().stack; + const stack = Error().stack!; return new Promise((resolve, reject) => { let readTime: Timestamp; this._stream(transactionId) .on('error', err => { - reject(wrapError(err, stack!)); + reject(wrapError(err, stack)); }) .on('data', result => { readTime = result.readTime; diff --git a/dev/src/util.ts b/dev/src/util.ts index 249f87ad3..d09cbe9d8 100644 --- a/dev/src/util.ts +++ b/dev/src/util.ts @@ -154,7 +154,7 @@ export function isPermanentRpcError( * @private */ export function wrapError(err: Error, stack: string): Error { - let wrappedError = new Error(err.message); + const wrappedError = new Error(err.message); wrappedError.stack += '\nCaused by: ' + stack; wrappedError.stack += '\nCaused by: ' + err.stack; return wrappedError; diff --git a/dev/src/write-batch.ts b/dev/src/write-batch.ts index d848a2d9e..408845189 100644 --- a/dev/src/write-batch.ts +++ b/dev/src/write-batch.ts @@ -532,12 +532,11 @@ export class WriteBatch { * }); */ commit(): Promise { - // Capture the error stack to preserve stack tracing across async calls. - const stack = Error().stack; + const stack = Error().stack!; return this.commit_().catch(err => { - throw wrapError(err, stack!); + throw wrapError(err, stack); }); } diff --git a/dev/system-test/firestore.ts b/dev/system-test/firestore.ts index 37b2b6b9d..974fbb106 100644 --- a/dev/system-test/firestore.ts +++ b/dev/system-test/firestore.ts @@ -2148,6 +2148,17 @@ describe('WriteBatch class', () => { }); }); + it('has a full stack trace if set() errors', () => { + // Use an invalid document name that the backend will reject. + const ref = randomCol.doc('__doc__'); + const batch = firestore.batch(); + batch.set(ref, {foo: 'a'}); + return batch.commit().then(() => Promise.reject('commit() should have failed') + ).catch((err: Error) => { + expect(err.stack).to.contain('WriteBatch.commit'); + }); + }); + it('has update() method', () => { const ref = randomCol.doc('doc'); const batch = firestore.batch();