Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: second size check
  • Loading branch information
durran committed Oct 9, 2024
commit bddc0b245696f51f526f9d5cd12cbf18bbd5e333
19 changes: 4 additions & 15 deletions src/operations/client_bulk_write/command_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class ClientBulkWriteCommandBuilder {
);
}

validateBufferSize('ops', operationBuffer, maxBsonObjectSize, maxMessageSizeBytes);
validateBufferSize('ops', operationBuffer, maxBsonObjectSize);

// Check if the operation buffer can fit in the command. If it can,
// then add the operation to the document sequence and increment the
Expand Down Expand Up @@ -172,8 +172,8 @@ export class ClientBulkWriteCommandBuilder {
);
}

validateBufferSize('nsInfo', nsInfoBuffer, maxBsonObjectSize, maxMessageSizeBytes);
validateBufferSize('ops', operationBuffer, maxBsonObjectSize, maxMessageSizeBytes);
validateBufferSize('nsInfo', nsInfoBuffer, maxBsonObjectSize);
validateBufferSize('ops', operationBuffer, maxBsonObjectSize);

// Check if the operation and nsInfo buffers can fit in the command. If they
// can, then add the operation and nsInfo to their respective document
Expand Down Expand Up @@ -231,23 +231,12 @@ export class ClientBulkWriteCommandBuilder {
}
}

function validateBufferSize(
name: string,
buffer: Uint8Array,
maxBsonObjectSize: number,
maxMessageSizeBytes: number
) {
function validateBufferSize(name: string, buffer: Uint8Array, maxBsonObjectSize: number) {
if (buffer.length > maxBsonObjectSize) {
throw new MongoInvalidArgumentError(
`Client bulk write operation ${name} of length ${buffer.length} exceeds the max bson object size of ${maxBsonObjectSize}`
);
}

if (buffer.length > maxMessageSizeBytes) {
throw new MongoInvalidArgumentError(
`Client bulk write operation ${name} of length ${buffer.length} exceeds the max message size size of ${maxMessageSizeBytes}`
);
}
}

/** @internal */
Expand Down