Skip to content

Commit 642d882

Browse files
committed
add some method names during client closed errors
1 parent 048c4b7 commit 642d882

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

src/collection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ export class Collection implements OperationParent {
655655
}
656656

657657
const topology = this.getTopology();
658-
if (!topology) throw new MongoClientClosedError();
658+
if (!topology) throw new MongoClientClosedError('Collection.prototype.find');
659659
return new Cursor(
660660
topology,
661661
new FindOperation(this, this.s.namespace, filter, options),
@@ -867,7 +867,7 @@ export class Collection implements OperationParent {
867867
*/
868868
listIndexes(options?: ListIndexesOptions): CommandCursor {
869869
const topology = this.getTopology();
870-
if (!topology) throw new MongoClientClosedError();
870+
if (!topology) throw new MongoClientClosedError('Collection.prototype.listIndexes');
871871
const cursor = new CommandCursor(topology, new ListIndexesOperation(this, options), options);
872872

873873
return cursor;
@@ -1213,7 +1213,7 @@ export class Collection implements OperationParent {
12131213
options = options || {};
12141214

12151215
const topology = this.getTopology();
1216-
if (!topology) throw new MongoClientClosedError();
1216+
if (!topology) throw new MongoClientClosedError('Collection.prototype.aggregate');
12171217
return new AggregationCursor(
12181218
topology,
12191219
new AggregateOperation(this, pipeline, options),

src/db.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ export class Db implements OperationParent {
311311

312312
options = options || {};
313313

314-
if (!this.s.client.topology) throw new MongoClientClosedError();
314+
if (!this.s.client.topology) throw new MongoClientClosedError('Db.prototype.aggregate');
315315
const cursor = new AggregationCursor(
316316
this.s.client.topology,
317317
new AggregateOperation(this, pipeline, options),
@@ -432,7 +432,7 @@ export class Db implements OperationParent {
432432
filter = filter || {};
433433
options = options || {};
434434

435-
if (!this.s.client.topology) throw new MongoClientClosedError();
435+
if (!this.s.client.topology) throw new MongoClientClosedError('Db.prototype.listCollections');
436436
return new CommandCursor(
437437
this.s.client.topology,
438438
new ListCollectionsOperation(this, filter, options),

src/operations/execute_operation.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ export function executeOperation<
6464
operation: T,
6565
callback?: Callback<TResult>
6666
): Promise<TResult> | void {
67-
if (topology == null) {
68-
throw new MongoClientClosedError();
69-
}
67+
if (!topology) throw new MongoClientClosedError();
7068

7169
if (!(operation instanceof OperationBase)) {
7270
throw new TypeError('This method requires a valid operation instance');

src/utils.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export function executeLegacyOperation<T extends OperationBase>(
270270
): void | Promise<any> {
271271
const Promise = PromiseProvider.get();
272272

273-
if (topology == null) throw new MongoClientClosedError();
273+
if (!topology) throw new MongoClientClosedError();
274274

275275
if (!Array.isArray(args)) {
276276
throw new TypeError('This method requires an array of arguments to apply');
@@ -439,9 +439,7 @@ export function decorateWithCollation(
439439
topology: Topology | undefined,
440440
options: AnyOptions
441441
): void {
442-
if (!topology) {
443-
throw new MongoClientClosedError();
444-
}
442+
if (!topology) throw new MongoClientClosedError();
445443

446444
const capabilities = topology.capabilities();
447445
if (options.collation && typeof options.collation === 'object') {

0 commit comments

Comments
 (0)