Skip to content

Commit

Permalink
add comments + test
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Chen committed May 21, 2020
1 parent 294ac2e commit 541449a
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions dev/src/bulk-writer.ts
Expand Up @@ -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);
});
}

Expand Down
4 changes: 2 additions & 2 deletions dev/src/index.ts
Expand Up @@ -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);
});
}

Expand Down
2 changes: 1 addition & 1 deletion dev/src/pool.ts
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions dev/src/reference.ts
Expand Up @@ -1809,14 +1809,14 @@ export class Query<T = DocumentData> {
const docs: Array<QueryDocumentSnapshot<T>> = [];

// 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;
Expand Down
2 changes: 1 addition & 1 deletion dev/src/util.ts
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions dev/src/write-batch.ts
Expand Up @@ -532,12 +532,11 @@ export class WriteBatch {
* });
*/
commit(): Promise<WriteResult[]> {

// 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);
});
}

Expand Down
11 changes: 11 additions & 0 deletions dev/system-test/firestore.ts
Expand Up @@ -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();
Expand Down

0 comments on commit 541449a

Please sign in to comment.