Skip to content

Commit

Permalink
smaller diff
Browse files Browse the repository at this point in the history
small small diff

snaller diff

temp

tests passing
  • Loading branch information
aditi-khare-mongoDB committed Jul 25, 2024
1 parent 623b5fc commit 355f05d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/bulk/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,8 @@ function handleMongoWriteConcernError(
callback(
new MongoBulkWriteError(
{
message: err?.result.writeConcernError.errmsg,
code: err?.result.writeConcernError.code
message: err.result.writeConcernError.errmsg,
code: err.result.writeConcernError.code
},
new BulkWriteResult(bulkResult, isOrdered)
)
Expand Down
15 changes: 7 additions & 8 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1169,8 +1169,9 @@ export interface WriteConcernErrorResult {
codeName?: string;
errInfo?: Document;
};
ok: 0 | 1;
ok: number;
code?: number;
errorLabels?: string[];
[x: string | number]: unknown;
}

Expand All @@ -1181,7 +1182,7 @@ export interface WriteConcernErrorResult {
*/
export class MongoWriteConcernError extends MongoServerError {
/** The result document */
result: WriteConcernErrorResult;
result: Document;

/**
* **Do not use this constructor!**
Expand All @@ -1195,10 +1196,10 @@ export class MongoWriteConcernError extends MongoServerError {
* @public
**/
constructor(result: WriteConcernErrorResult) {
super(result);
this.errInfo = result.writeConcernError?.errInfo;
super({ ...result, ...result.writeConcernError });
this.errInfo = result.writeConcernError.errInfo;
this.result = result;
this.code = result.code ? result.code : undefined;
this.code = result.code ?? result.writeConcernError.code ?? undefined;
}

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

if (error instanceof MongoWriteConcernError) {
return RETRYABLE_WRITE_ERROR_CODES.has(
error.result.writeConcernError?.code ?? error?.code ?? 0
);
return RETRYABLE_WRITE_ERROR_CODES.has(error.result?.code ?? error.code ?? 0);
}

if (error instanceof MongoError && typeof error.code === 'number') {
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export {
MongoTopologyClosedError,
MongoTransactionError,
MongoUnexpectedServerResponseError,
MongoWriteConcernError
MongoWriteConcernError,
WriteConcernErrorResult
} from './error';
export {
AbstractCursor,
Expand Down
13 changes: 6 additions & 7 deletions test/unit/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ import {
setDifference,
type TopologyDescription,
type TopologyOptions,
WaitQueueTimeoutError as MongoWaitQueueTimeoutError,
WriteConcernErrorResult
WaitQueueTimeoutError as MongoWaitQueueTimeoutError
} from '../mongodb';
import { ReplSetFixture } from '../tools/common';
import { cleanup } from '../tools/mongodb-mock/index';
Expand Down Expand Up @@ -743,22 +742,22 @@ describe('MongoErrors', () => {
});

describe('MongoWriteConcernError constructor', function () {
context('when no top-level code is provided and writeConcernError.code exists', function () {
it('error.code remains undefined', function () {
const res: WriteConcernErrorResult = {
context('when no top-level code is provided', function () {
it('error.code is set to writeConcernError.code', function () {
const res = {
writeConcernError: {
code: 81, // nested code
errmsg: 'fake msg'
},
ok: 1
};
expect(new MongoWriteConcernError(res).code).to.equal(undefined);
expect(new MongoWriteConcernError(res).code).to.equal(81);
});
});
context('when top-level code is provided and writeConcernError.code exists', function () {
it('error.code equals the top-level code', function () {
const topLevelCode = 10;
const res: WriteConcernErrorResult = {
const res = {
writeConcernError: {
code: 81, // nested code
errmsg: 'fake msg'
Expand Down
2 changes: 1 addition & 1 deletion test/unit/mongo_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ describe('MongoClient', function () {
expect(error).to.have.property('code', 'EBADNAME');
});

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

0 comments on commit 355f05d

Please sign in to comment.