{"record":{"id":"fb5885b6e25c23b4","repo":"mongodb/node-mongodb-native","slug":"user-input-for-option-mongodblogcomponentseveriti","errorCode":null,"errorMessage":"User input for option 'mongodbLogComponentSeverities' object cannot include a non-string key or value","messagePattern":"User input for option 'mongodbLogComponentSeverities' object cannot include a non-string key or value","errorType":"exception","errorClass":"MongoAPIError","httpStatus":null,"severity":"error","filePath":"src/connection_string.ts","lineNumber":1261,"sourceCode":"            'write' in value &&\n            typeof value.write === 'function')\n        )\n      ) {\n        throw new MongoAPIError(\n          `Option 'mongodbLogPath' must be of type 'stderr' | 'stdout' | MongoDBLogWritable`\n        );\n      }\n      return value;\n    }\n  },\n  mongodbLogComponentSeverities: {\n    transform({ values: [value] }) {\n      if (typeof value !== 'object' || !value) {\n        throw new MongoAPIError(`Option 'mongodbLogComponentSeverities' must be a non-null object`);\n      }\n      for (const [k, v] of Object.entries(value)) {\n        if (typeof v !== 'string' || typeof k !== 'string') {\n          throw new MongoAPIError(\n            `User input for option 'mongodbLogComponentSeverities' object cannot include a non-string key or value`\n          );\n        }\n        if (!Object.values(MongoLoggableComponent).some(val => val === k) && k !== 'default') {\n          throw new MongoAPIError(\n            `User input for option 'mongodbLogComponentSeverities' contains invalid key: ${k}`\n          );\n        }\n        if (!Object.values(SeverityLevel).some(val => val === v)) {\n          throw new MongoAPIError(\n            `Option 'mongodbLogComponentSeverities' does not support ${v} as a value for ${k}`\n          );\n        }\n      }\n      return value;\n    }\n  },\n  mongodbLogMaxDocumentLength: { type: 'uint' },","sourceCodeStart":1243,"sourceCodeEnd":1279,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/connection_string.ts#L1243-L1279","documentation":"After confirming the value is a non-null object, the transform at src/connection_string.ts:1259 iterates entries and requires BOTH the key and the value to be strings. If any value is non-string (e.g. a numeric severity) or any key is non-string (e.g. a symbol/number), MongoAPIError is thrown at src/connection_string.ts:1261.","triggerScenarios":"Passing `mongodbLogComponentSeverities: { command: 3 }` (numeric severity from a syslog table); `{ 0: 'debug' }` (numeric key); `{ command: true }` (boolean toggle).","commonSituations":"Copying numeric syslog severities from documentation; using config formats that auto-coerce keys to numbers; treating severities as on/off booleans.","solutions":["Use string severity names for every value: `{ command: 'error' }`.","Quote numeric-looking keys or keep keys as component names: `{ command: 'debug' }`.","Validate every entry is `[string, string]` before constructing the client."],"exampleFix":"// before\nnew MongoClient(uri, { mongodbLogComponentSeverities: { command: 3 } });\n\n// after\nnew MongoClient(uri, { mongodbLogComponentSeverities: { command: 'error' } });","handlingStrategy":"validation","validationCode":"if (opts.mongodbLogComponentSeverities) {\n  for (const [k, v] of Object.entries(opts.mongodbLogComponentSeverities as Record<string, unknown>)) {\n    if (typeof k !== 'string' || typeof v !== 'string') {\n      throw new Error(`component severity entry ${k} must be [string, string]`);\n    }\n  }\n}","typeGuard":"function isStringStringRecord(v: unknown): v is Record<string, string> { return typeof v === 'object' && v !== null && Object.entries(v).every(([k, val]) => typeof k === 'string' && typeof val === 'string'); }","tryCatchPattern":"try { client = new MongoClient(uri, opts); } catch (e) { if (e instanceof MongoAPIError && /non-string key or value/.test(e.message)) { opts.mongodbLogComponentSeverities = { default: 'info' }; client = new MongoClient(uri, opts); } else throw e; }","preventionTips":["Use string severity names everywhere, not numbers.","Quote any numeric-looking keys in config files.","Validate the record type at the config boundary."],"tags":["logging","configuration","type-error"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}