Skip to content

Commit 070a84a

Browse files
committed
throw instead of warn.
1 parent fbfa24f commit 070a84a

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

packages/firestore/src/api/snapshot.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import {
4242
QuerySnapshotBundleData
4343
} from '../util/bundle_builder_impl';
4444
import { Code, FirestoreError } from '../util/error';
45-
import { logWarn } from '../util/log';
4645
import { AutoId } from '../util/misc';
4746

4847
import { Firestore } from './database';
@@ -522,8 +521,10 @@ export class DocumentSnapshot<
522521
'previous'
523522
);
524523
if (documentData.hasPendingWrites) {
525-
logWarn(
526-
'DocumentSnapshot.toJSON serialized a document with pending writes. The pending writes will not be serialized.'
524+
throw new FirestoreError(
525+
Code.FAILED_PRECONDITION,
526+
'DocumentSnapshot.toJSON attempted to serialize a document with pending writes. ' +
527+
'Await `waitForPendingWrites()` before invoking `toJSON()`.'
527528
);
528529
}
529530
builder.addBundleDocument(
@@ -710,8 +711,10 @@ export class QuerySnapshot<
710711
'previous'
711712
);
712713
if (documentData.hasPendingWrites) {
713-
logWarn(
714-
'QuerySnapshot.toJSON serialized a document with pending writes. The pending writes will not be serialized.'
714+
throw new FirestoreError(
715+
Code.FAILED_PRECONDITION,
716+
'QuerySnapshot.toJSON attempted to serialize a document with pending writes. ' +
717+
'Await `waitForPendingWrites()` before invoking `toJSON()`.'
715718
);
716719
}
717720
docBundleDataArray.push(

packages/firestore/src/util/bundle_builder_impl.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ import {
4646
} from '../protos/firestore_proto_api';
4747
import { AutoId } from '../util/misc';
4848

49-
import { debugAssert } from './assert';
50-
5149
const BUNDLE_VERSION = 1;
5250

5351
/**
@@ -107,9 +105,7 @@ export class BundleBuilder {
107105
: null;
108106

109107
const neitherHasReadTime: boolean = !docReadTime && origDocReadTime == null;
110-
const docIsNewer: boolean =
111-
docReadTime !== undefined &&
112-
(origDocReadTime == null || origDocReadTime < docReadTime);
108+
const docIsNewer: boolean = docReadTime !== undefined && (origDocReadTime == null || origDocReadTime < docReadTime);
113109
if (neitherHasReadTime || docIsNewer) {
114110
// Store document.
115111
this.documents.set(docBundleData.documentPath, {
@@ -122,7 +118,7 @@ export class BundleBuilder {
122118
exists: docBundleData.documentExists
123119
}
124120
});
125-
}
121+
}
126122
if (docReadTime && docReadTime > this.latestReadTime) {
127123
this.latestReadTime = docReadTime;
128124
}

0 commit comments

Comments
 (0)