@@ -2,7 +2,7 @@ import * as os from 'os';
22import * as process from 'process' ;
33
44import { BSON , type Document , Int32 } from '../../bson' ;
5- import { MongoInvalidArgumentError } from '../../error' ;
5+ import { MongoInvalidArgumentError , MongoRuntimeError } from '../../error' ;
66import type { MongoOptions } from '../../mongo_client' ;
77import { fileIsAccessible } from '../../utils' ;
88
@@ -122,15 +122,19 @@ export function makeClientMetadata(options: MakeClientMetadataOptions): ClientMe
122122 version : version . length > 0 ? `${ NODE_DRIVER_VERSION } |${ version } ` : NODE_DRIVER_VERSION
123123 } ;
124124
125+ if ( options . additionalDriverInfo == null ) {
126+ throw new MongoRuntimeError (
127+ 'Client options `additionalDriverInfo` must always default to an empty array'
128+ ) ;
129+ }
130+
125131 // This is where we handle additional driver info added after client construction.
126- if ( options . additionalDriverInfo ?. length > 0 ) {
127- for ( const { name : n = '' , version : v = '' } of options . additionalDriverInfo ) {
128- if ( n . length > 0 ) {
129- driverInfo . name = `${ driverInfo . name } |${ n } ` ;
130- }
131- if ( v . length > 0 ) {
132- driverInfo . version = `${ driverInfo . version } |${ v } ` ;
133- }
132+ for ( const { name : n = '' , version : v = '' } of options . additionalDriverInfo ) {
133+ if ( n . length > 0 ) {
134+ driverInfo . name = `${ driverInfo . name } |${ n } ` ;
135+ }
136+ if ( v . length > 0 ) {
137+ driverInfo . version = `${ driverInfo . version } |${ v } ` ;
134138 }
135139 }
136140
@@ -145,11 +149,9 @@ export function makeClientMetadata(options: MakeClientMetadataOptions): ClientMe
145149 runtimeInfo = `${ runtimeInfo } |${ platform } ` ;
146150 }
147151
148- if ( options . additionalDriverInfo ?. length > 0 ) {
149- for ( const { platform : p = '' } of options . additionalDriverInfo ) {
150- if ( p . length > 0 ) {
151- runtimeInfo = `${ runtimeInfo } |${ p } ` ;
152- }
152+ for ( const { platform : p = '' } of options . additionalDriverInfo ) {
153+ if ( p . length > 0 ) {
154+ runtimeInfo = `${ runtimeInfo } |${ p } ` ;
153155 }
154156 }
155157
0 commit comments