{"record":{"id":"effd8b727856824a","repo":"mongodb/node-mongodb-native","slug":"unable-to-include-driverinfo-platform-metadata-ca","errorCode":null,"errorMessage":"Unable to include driverInfo platform, metadata cannot exceed 512 bytes","messagePattern":"Unable to include driverInfo platform, metadata cannot exceed 512 bytes","errorType":"exception","errorClass":"MongoInvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/cmap/handshake/client_metadata.ts","lineNumber":154,"sourceCode":"    }\n  }\n\n  if (!metadataDocument.ifItFitsItSits('driver', driverInfo)) {\n    throw new MongoInvalidArgumentError(\n      'Unable to include driverInfo name and version, metadata cannot exceed 512 bytes'\n    );\n  }\n\n  let runtimeInfo = getRuntimeInfo();\n  // This is where we handle additional driver info added after client construction.\n  for (const { platform = '' } of driverInfoList) {\n    if (platform.length > 0) {\n      runtimeInfo = `${runtimeInfo}|${platform}`;\n    }\n  }\n\n  if (!metadataDocument.ifItFitsItSits('platform', runtimeInfo)) {\n    throw new MongoInvalidArgumentError(\n      'Unable to include driverInfo platform, metadata cannot exceed 512 bytes'\n    );\n  }\n\n  // Note: order matters, os.type is last so it will be removed last if we're at maxSize\n  const osInfo = new Map()\n    .set('name', os.platform())\n    .set('architecture', os.arch())\n    .set('version', os.release())\n    .set('type', os.type());\n\n  if (!metadataDocument.ifItFitsItSits('os', osInfo)) {\n    for (const key of osInfo.keys()) {\n      osInfo.delete(key);\n      if (osInfo.size === 0) break;\n      if (metadataDocument.ifItFitsItSits('os', osInfo)) break;\n    }\n  }","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/cmap/handshake/client_metadata.ts#L136-L172","documentation":"A MongoInvalidArgumentError thrown in makeClientMetadata when the platform string (runtime info + custom driverInfo.platform segments) cannot fit within the 512-byte metadata limit after application and driver blocks were added. The platform field accumulates runtime info like 'Node.js vXX, LE' plus any user-supplied driverInfo.platform values joined with '|'.","triggerScenarios":"Supplying a long driverInfo.platform string, or multiple driverInfo contributors with platform segments, such that the total BSON metadata exceeds 512 bytes once driver and app name are included.","commonSituations":"Embedding long diagnostic/architecture tags in driverInfo.platform; multiple libraries each appending platform metadata; long appName compounding the overflow.","solutions":["Shorten driverInfo.platform values.","Shorten appName to leave room.","Consolidate multiple platform contributors.","Validate total metadata size at startup."],"exampleFix":"// before\nconst client = new MongoClient(uri, {\n  driverInfo: { platform: 'P'.repeat(500) }\n});\n\n// after\nconst client = new MongoClient(uri, {\n  driverInfo: { platform: 'edge-region-eu' }\n});","handlingStrategy":"validation","validationCode":"const platformBytes = Buffer.byteLength(driverInfo.platform ?? '', 'utf8');\nif (platformBytes > 200) {\n  throw new Error('driverInfo.platform too large for 512-byte metadata limit');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep driverInfo.platform concise.","Avoid stacking many platform contributors.","Validate total metadata size at startup."],"tags":["handshake","metadata","config","startup"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}