{"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/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/connection_string.ts#L1243-L1279","documentation":"Thrown while iterating entries of mongodbLogComponentSeverities when a key or value is not a string. Both keys (component names) and values (severity levels) must be string-typed; non-string keys can appear via numeric object keys, and non-string values via booleans/numbers.","triggerScenarios":"Passing { command: 1 } (numeric severity), { 0: 'debug' } (numeric key auto-coerced), { command: true }, or any entry where Object.entries yields a non-string side. Symbol-keyed entries are excluded by Object.entries but numeric literals become string keys so the value side is the usual culprit.","commonSituations":"Porting a config where severities were numbers (e.g. syslog-style 0-7); loading config from YAML that parsed severity as an int; copy-pasting example that used unquoted numbers.","solutions":["Quote all severity values: { command: 'debug' } not { command: 1 }.","Ensure config loaders (YAML/ENV parsers) emit strings — quote values or cast with String().","Validate the object shape before constructing MongoClient."],"exampleFix":"// before\nnew MongoClient(uri, { mongodbLogComponentSeverities: { command: 1 } });\n// after\nnew MongoClient(uri, { mongodbLogComponentSeverities: { command: 'debug' } });","handlingStrategy":"validation","validationCode":"function validateSeverities(o) {\n  for (const [k, v] of Object.entries(o)) {\n    if (typeof k !== 'string' || typeof v !== 'string') return false;\n  }\n  return true;\n}","typeGuard":"function isStringRecord(o): o is Record<string, string> {\n  return Object.values(o).every(v => typeof v === 'string');\n}","tryCatchPattern":null,"preventionTips":["Quote severity values in YAML/JSON config to avoid numeric parsing.","Cast config values with String() before constructing MongoClient.","Add a schema validator (zod/joi) for log-severity config."],"tags":["logging","options","configuration","type-validation"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}