Skip to content

Commit c9e5402

Browse files
committed
consistent intentional ignore error handlers
1 parent 9d48c79 commit c9e5402

File tree

5 files changed

+8
-30
lines changed

5 files changed

+8
-30
lines changed

src/change_stream.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -894,10 +894,7 @@ export class ChangeStream<
894894

895895
if (isResumableError(changeStreamError, this.cursor.maxWireVersion)) {
896896
this._endStream();
897-
this.cursor.close().then(
898-
() => null,
899-
() => null
900-
); // Ignoring the result of close is intentional
897+
this.cursor.close().catch(() => null);
901898

902899
const topology = getTopology(this.parent);
903900
topology.selectServer(this.cursor.readPreference, {}, serverSelectionError => {
@@ -927,10 +924,7 @@ export class ChangeStream<
927924
}
928925

929926
if (isResumableError(changeStreamError, this.cursor.maxWireVersion)) {
930-
this.cursor.close().then(
931-
() => null,
932-
() => null
933-
); // Ignoring the result of close is intentional
927+
this.cursor.close().catch(() => null);
934928

935929
const topology = getTopology(this.parent);
936930
topology.selectServer(this.cursor.readPreference, {}, serverSelectionError => {

src/cursor/abstract_cursor.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ export abstract class AbstractCursor<
597597
// We only want to end this session if we created it, and it hasn't ended yet
598598
if (session.explicit === false) {
599599
if (!session.hasEnded) {
600-
session.endSession(() => null);
600+
session.endSession().catch(() => null);
601601
}
602602
this[kSession] = this.client.startSession({ owner: this, explicit: false });
603603
}
@@ -883,10 +883,7 @@ class ReadableCursorStream extends Readable {
883883
// a client during iteration. Alternatively, we could do the "right" thing and
884884
// propagate the error message by removing this special case.
885885
if (err.message.match(/server is closed/)) {
886-
this._cursor.close().then(
887-
() => null,
888-
() => null
889-
); // Ignoring the result of close is intentional
886+
this._cursor.close().catch(() => null);
890887
return this.push(null);
891888
}
892889

@@ -905,10 +902,7 @@ class ReadableCursorStream extends Readable {
905902
if (result == null) {
906903
this.push(null);
907904
} else if (this.destroyed) {
908-
this._cursor.close().then(
909-
() => null,
910-
() => null
911-
); // Ignoring the result of close is intentional
905+
this._cursor.close().catch(() => null);
912906
} else {
913907
if (this.push(result)) {
914908
return this._readNext();

src/mongo_client.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,6 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
493493
{ endSessions },
494494
{ readPreference: ReadPreference.primaryPreferred, noResponse: true }
495495
)
496-
.then(() => null) // outcome does not matter
497496
.catch(() => null); // outcome does not matter
498497
})
499498
.then(() => {
@@ -639,10 +638,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
639638
// Do not return the result of callback
640639
})
641640
.finally(() => {
642-
session.endSession().then(
643-
() => null,
644-
() => null
645-
);
641+
session.endSession().catch(() => null);
646642
});
647643
}
648644

src/operations/execute_operation.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,7 @@ export function executeOperation<
144144
});
145145
} catch (error) {
146146
if (session?.owner != null && session.owner === owner) {
147-
session.endSession().then(
148-
() => null,
149-
() => null
150-
); // Ignoring the result of endSession is intentional
147+
session.endSession().catch(() => null);
151148
}
152149

153150
throw error;

src/sessions.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -616,10 +616,7 @@ function attemptTransaction<TSchema>(
616616
}
617617

618618
if (!isPromiseLike(promise)) {
619-
session.abortTransaction().then(
620-
() => null,
621-
() => null
622-
); // TODO(NODE-XXXX): is this correct?
619+
session.abortTransaction().catch(() => null);
623620
throw new MongoInvalidArgumentError(
624621
'Function provided to `withTransaction` must return a Promise'
625622
);

0 commit comments

Comments
 (0)