Skip to content

Commit 3857159

Browse files
committed
fix: some comments
1 parent 5007a03 commit 3857159

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/operations/execute_operation.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,21 @@ export function executeOperation<
7878
return maybeCallback(() => executeOperationAsync(client, operation), callback);
7979
}
8080

81-
async function assertTopology(client: MongoClient) {
81+
async function maybeConnect(client: MongoClient): Promise<Topology> {
8282
const { topology } = client;
8383
if (topology == null) {
8484
if (client.s.hasBeenClosed) {
8585
throw new MongoNotConnectedError('Client must be connected before running operations');
8686
}
8787
client.s.options[Symbol.for('@@mdb.skipPingOnConnect')] = true;
88-
await client.connect();
89-
delete client.s.options[Symbol.for('@@mdb.skipPingOnConnect')];
88+
try {
89+
await client.connect();
90+
} finally {
91+
delete client.s.options[Symbol.for('@@mdb.skipPingOnConnect')];
92+
}
9093
}
9194
if (client.topology == null) {
92-
throw new MongoNotConnectedError('Client must be connected before running operations');
95+
throw new MongoRuntimeError('client.connect did not create a topology but also did not throw');
9396
}
9497
return client.topology;
9598
}
@@ -103,7 +106,7 @@ async function executeOperationAsync<
103106
throw new MongoRuntimeError('This method requires a valid operation instance');
104107
}
105108

106-
const topology = await assertTopology(client);
109+
const topology = await maybeConnect(client);
107110

108111
if (topology.shouldCheckForSessionSupport()) {
109112
await topology.selectServerAsync(ReadPreference.primaryPreferred, {});

src/operations/rename.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ export class RenameOperation extends RunAdminCommandOperation {
3838
this.newName = newName;
3939
}
4040

41-
override execute(server: Server, session: ClientSession | undefined, callback: Callback): void {
41+
override execute(
42+
server: Server,
43+
session: ClientSession | undefined,
44+
callback: Callback<Collection>
45+
): void {
4246
const coll = this.collection;
4347

4448
super.execute(server, session, (err, doc) => {

src/operations/stats.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ export class CollStatsOperation extends CommandOperation<Document> {
3333
this.collectionName = collection.collectionName;
3434
}
3535

36-
override execute(server: Server, session: ClientSession | undefined, callback: Callback): void {
36+
override execute(
37+
server: Server,
38+
session: ClientSession | undefined,
39+
callback: Callback<CollStats>
40+
): void {
3741
const command: Document = { collStats: this.collectionName };
3842
if (this.options.scale != null) {
3943
command.scale = this.options.scale;

0 commit comments

Comments
 (0)