Skip to content

Commit 147e78b

Browse files
committed
push down error check to decorate with collation
1 parent 631db82 commit 147e78b

File tree

6 files changed

+9
-13
lines changed

6 files changed

+9
-13
lines changed

src/operations/common_functions.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MongoClientClosedError, MongoError } from '../error';
1+
import { MongoError } from '../error';
22
import { applyRetryableWrites, applyWriteConcern, decorateWithCollation, Callback } from '../utils';
33
import type { Document } from '../bson';
44
import type { Db } from '../db';
@@ -152,7 +152,6 @@ export function removeDocuments(
152152

153153
// Have we specified collation
154154
try {
155-
if (!coll.topology) throw new MongoClientClosedError();
156155
decorateWithCollation(finalOptions, coll.topology, options);
157156
} catch (err) {
158157
return callback ? callback(err, null) : undefined;
@@ -244,7 +243,6 @@ export function updateDocuments(
244243

245244
// Have we specified collation
246245
try {
247-
if (!coll.topology) throw new MongoClientClosedError();
248246
decorateWithCollation(finalOptions, coll.topology, options);
249247
} catch (err) {
250248
return callback(err, null);

src/operations/count.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type { Document } from '../bson';
55
import type { Server } from '../sdam/server';
66
import type { Collection } from '../collection';
77
import type { Cursor } from '../cursor/cursor';
8-
import { MongoClientClosedError } from '../error';
98

109
/** @public */
1110
export interface CountOptions extends CommandOperationOptions {
@@ -106,7 +105,6 @@ function buildCountCommand(
106105
}
107106
decorateWithCollation(cmd, collectionOrCursor.topology, collectionOrCursor.cmd);
108107
} else {
109-
if (!collectionOrCursor.topology) throw new MongoClientClosedError();
110108
decorateWithCollation(cmd, collectionOrCursor.topology, options);
111109
}
112110

src/operations/distinct.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { decorateWithCollation, decorateWithReadConcern, Callback } from '../uti
44
import type { Document } from '../bson';
55
import type { Server } from '../sdam/server';
66
import type { Collection } from '../collection';
7-
import { MongoClientClosedError } from '../error';
87

98
/** @public */
109
export type DistinctOptions = CommandOperationOptions;
@@ -56,7 +55,6 @@ export class DistinctOperation extends CommandOperation<DistinctOptions, Documen
5655

5756
// Have we specified collation
5857
try {
59-
if (!coll.topology) throw new MongoClientClosedError();
6058
decorateWithCollation(cmd, coll.topology, options);
6159
} catch (err) {
6260
return callback(err);

src/operations/find_and_modify.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
hasAtomicOperators,
88
Callback
99
} from '../utils';
10-
import { MongoClientClosedError, MongoError } from '../error';
10+
import { MongoError } from '../error';
1111
import { CommandOperation, CommandOperationOptions } from './command';
1212
import { defineAspects, Aspect } from './operation';
1313
import type { Document } from '../bson';
@@ -127,7 +127,6 @@ export class FindAndModifyOperation extends CommandOperation<FindAndModifyOption
127127

128128
// Have we specified collation
129129
try {
130-
if (!coll.topology) throw new MongoClientClosedError();
131130
decorateWithCollation(cmd, coll.topology, options);
132131
} catch (err) {
133132
return callback(err);

src/operations/map_reduce.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { CommandOperation, CommandOperationOptions } from './command';
1212
import type { Server } from '../sdam/server';
1313
import type { Collection } from '../collection';
1414
import type { Sort } from '../sort';
15-
import { MongoClientClosedError, MongoError } from '../error';
15+
import { MongoError } from '../error';
1616
import type { ObjectId } from '../bson';
1717

1818
const exclusionList = [
@@ -144,7 +144,6 @@ export class MapReduceOperation extends CommandOperation<MapReduceOptions, Docum
144144

145145
// Have we specified collation
146146
try {
147-
if (!coll.topology) throw new MongoClientClosedError();
148147
decorateWithCollation(mapCommandHash, coll.topology, options);
149148
} catch (err) {
150149
return callback(err);

src/utils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as os from 'os';
22
import * as crypto from 'crypto';
33
import { PromiseProvider } from './promise_provider';
4-
import { MongoError, AnyError } from './error';
4+
import { MongoError, AnyError, MongoClientClosedError } from './error';
55
import { WriteConcern, WriteConcernOptions, W, writeConcernKeys } from './write_concern';
66
import type { Server } from './sdam/server';
77
import type { Topology } from './sdam/topology';
@@ -438,9 +438,13 @@ export function isPromiseLike<T = any>(
438438
*/
439439
export function decorateWithCollation(
440440
command: Document,
441-
topology: Topology,
441+
topology: Topology | undefined,
442442
options: AnyOptions
443443
): void {
444+
if (!topology) {
445+
throw new MongoClientClosedError();
446+
}
447+
444448
const capabilities = topology.capabilities();
445449
if (options.collation && typeof options.collation === 'object') {
446450
if (capabilities && capabilities.commandsTakeCollation) {

0 commit comments

Comments
 (0)