Skip to content

Commit 355f05d

Browse files
smaller diff
small small diff snaller diff temp tests passing
1 parent 623b5fc commit 355f05d

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

src/bulk/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,8 @@ function handleMongoWriteConcernError(
616616
callback(
617617
new MongoBulkWriteError(
618618
{
619-
message: err?.result.writeConcernError.errmsg,
620-
code: err?.result.writeConcernError.code
619+
message: err.result.writeConcernError.errmsg,
620+
code: err.result.writeConcernError.code
621621
},
622622
new BulkWriteResult(bulkResult, isOrdered)
623623
)

src/error.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,8 +1169,9 @@ export interface WriteConcernErrorResult {
11691169
codeName?: string;
11701170
errInfo?: Document;
11711171
};
1172-
ok: 0 | 1;
1172+
ok: number;
11731173
code?: number;
1174+
errorLabels?: string[];
11741175
[x: string | number]: unknown;
11751176
}
11761177

@@ -1181,7 +1182,7 @@ export interface WriteConcernErrorResult {
11811182
*/
11821183
export class MongoWriteConcernError extends MongoServerError {
11831184
/** The result document */
1184-
result: WriteConcernErrorResult;
1185+
result: Document;
11851186

11861187
/**
11871188
* **Do not use this constructor!**
@@ -1195,10 +1196,10 @@ export class MongoWriteConcernError extends MongoServerError {
11951196
* @public
11961197
**/
11971198
constructor(result: WriteConcernErrorResult) {
1198-
super(result);
1199-
this.errInfo = result.writeConcernError?.errInfo;
1199+
super({ ...result, ...result.writeConcernError });
1200+
this.errInfo = result.writeConcernError.errInfo;
12001201
this.result = result;
1201-
this.code = result.code ? result.code : undefined;
1202+
this.code = result.code ?? result.writeConcernError.code ?? undefined;
12021203
}
12031204

12041205
override get name(): string {
@@ -1246,9 +1247,7 @@ export function needsRetryableWriteLabel(error: Error, maxWireVersion: number):
12461247
}
12471248

12481249
if (error instanceof MongoWriteConcernError) {
1249-
return RETRYABLE_WRITE_ERROR_CODES.has(
1250-
error.result.writeConcernError?.code ?? error?.code ?? 0
1251-
);
1250+
return RETRYABLE_WRITE_ERROR_CODES.has(error.result?.code ?? error.code ?? 0);
12521251
}
12531252

12541253
if (error instanceof MongoError && typeof error.code === 'number') {

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ export {
7373
MongoTopologyClosedError,
7474
MongoTransactionError,
7575
MongoUnexpectedServerResponseError,
76-
MongoWriteConcernError
76+
MongoWriteConcernError,
77+
WriteConcernErrorResult
7778
} from './error';
7879
export {
7980
AbstractCursor,

test/unit/error.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ import {
3030
setDifference,
3131
type TopologyDescription,
3232
type TopologyOptions,
33-
WaitQueueTimeoutError as MongoWaitQueueTimeoutError,
34-
WriteConcernErrorResult
33+
WaitQueueTimeoutError as MongoWaitQueueTimeoutError
3534
} from '../mongodb';
3635
import { ReplSetFixture } from '../tools/common';
3736
import { cleanup } from '../tools/mongodb-mock/index';
@@ -743,22 +742,22 @@ describe('MongoErrors', () => {
743742
});
744743

745744
describe('MongoWriteConcernError constructor', function () {
746-
context('when no top-level code is provided and writeConcernError.code exists', function () {
747-
it('error.code remains undefined', function () {
748-
const res: WriteConcernErrorResult = {
745+
context('when no top-level code is provided', function () {
746+
it('error.code is set to writeConcernError.code', function () {
747+
const res = {
749748
writeConcernError: {
750749
code: 81, // nested code
751750
errmsg: 'fake msg'
752751
},
753752
ok: 1
754753
};
755-
expect(new MongoWriteConcernError(res).code).to.equal(undefined);
754+
expect(new MongoWriteConcernError(res).code).to.equal(81);
756755
});
757756
});
758757
context('when top-level code is provided and writeConcernError.code exists', function () {
759758
it('error.code equals the top-level code', function () {
760759
const topLevelCode = 10;
761-
const res: WriteConcernErrorResult = {
760+
const res = {
762761
writeConcernError: {
763762
code: 81, // nested code
764763
errmsg: 'fake msg'

test/unit/mongo_client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ describe('MongoClient', function () {
737737
expect(error).to.have.property('code', 'EBADNAME');
738738
});
739739

740-
it.only('srvServiceName should not error if it is greater than 15 characters as long as the DNS query limit is not surpassed', async () => {
740+
it('srvServiceName should not error if it is greater than 15 characters as long as the DNS query limit is not surpassed', async () => {
741741
const options = parseOptions('mongodb+srv://localhost.a.com', {
742742
srvServiceName: 'a'.repeat(16)
743743
});

0 commit comments

Comments
 (0)