From 30432e8664cb142e999159e5d06ceaaf14f51eb8 Mon Sep 17 00:00:00 2001 From: Aditi Khare <106987683+aditi-khare-mongoDB@users.noreply.github.com> Date: Thu, 14 Mar 2024 10:34:23 -0400 Subject: [PATCH] fix(NODE-5999): Change TopologyDescription.error type to MongoError (#4028) --- src/sdam/server.ts | 6 +++--- src/sdam/server_description.ts | 4 ++-- src/sdam/topology_description.ts | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/sdam/server.ts b/src/sdam/server.ts index 8d552df360..89f154eaac 100644 --- a/src/sdam/server.ts +++ b/src/sdam/server.ts @@ -357,7 +357,7 @@ export class Server extends TypedEventEmitter { // clear for the specific service id. if (!this.loadBalanced) { error.addErrorLabel(MongoErrorLabel.ResetPool); - markServerUnknown(this, error as MongoServerError); + markServerUnknown(this, error); } else if (connection) { this.pool.clear({ serviceId: connection.serviceId }); } @@ -373,7 +373,7 @@ export class Server extends TypedEventEmitter { if (shouldClearPool) { error.addErrorLabel(MongoErrorLabel.ResetPool); } - markServerUnknown(this, error as MongoServerError); + markServerUnknown(this, error); process.nextTick(() => this.requestCheck()); } } @@ -476,7 +476,7 @@ function calculateRoundTripTime(oldRtt: number, duration: number): number { return alpha * duration + (1 - alpha) * oldRtt; } -function markServerUnknown(server: Server, error?: MongoServerError) { +function markServerUnknown(server: Server, error?: MongoError) { // Load balancer servers can never be marked unknown. if (server.loadBalanced) { return; diff --git a/src/sdam/server_description.ts b/src/sdam/server_description.ts index 62fe0aadde..ec9b1939db 100644 --- a/src/sdam/server_description.ts +++ b/src/sdam/server_description.ts @@ -1,5 +1,5 @@ import { type Document, Long, type ObjectId } from '../bson'; -import { type MongoError, MongoRuntimeError, type MongoServerError } from '../error'; +import { type MongoError, MongoRuntimeError } from '../error'; import { arrayStrictEqual, compareObjectId, errorStrictEqual, HostAddress, now } from '../utils'; import type { ClusterTime } from './common'; import { ServerType } from './common'; @@ -31,7 +31,7 @@ export type TagSet = { [key: string]: string }; /** @internal */ export interface ServerDescriptionOptions { /** An Error used for better reporting debugging */ - error?: MongoServerError; + error?: MongoError; /** The round trip time to ping this server (in ms) */ roundTripTime?: number; diff --git a/src/sdam/topology_description.ts b/src/sdam/topology_description.ts index f2fafaf87b..5073429866 100644 --- a/src/sdam/topology_description.ts +++ b/src/sdam/topology_description.ts @@ -1,6 +1,6 @@ import type { ObjectId } from '../bson'; import * as WIRE_CONSTANTS from '../cmap/wire_protocol/constants'; -import { MongoRuntimeError, type MongoServerError } from '../error'; +import { type MongoError, MongoRuntimeError } from '../error'; import { compareObjectId, shuffle } from '../utils'; import { ServerType, TopologyType } from './common'; import { ServerDescription } from './server_description'; @@ -307,13 +307,13 @@ export class TopologyDescription { ); } - get error(): MongoServerError | null { + get error(): MongoError | null { const descriptionsWithError = Array.from(this.servers.values()).filter( (sd: ServerDescription) => sd.error ); if (descriptionsWithError.length > 0) { - return descriptionsWithError[0].error as MongoServerError; + return descriptionsWithError[0].error; } return null;