{"id":"f76cd27c313b6475","repo":"mongodb/node-mongodb-native","slug":"option-mongodblogcomponentseverities-must-be-a-n","errorCode":null,"errorMessage":"Option 'mongodbLogComponentSeverities' must be a non-null object","messagePattern":"Option 'mongodbLogComponentSeverities' must be a non-null object","errorType":"exception","errorClass":"MongoAPIError","httpStatus":null,"severity":"error","filePath":"src/connection_string.ts","lineNumber":1257,"sourceCode":"        !(\n          (typeof value === 'string' && ['stderr', 'stdout'].includes(value)) ||\n          (value &&\n            typeof value === 'object' &&\n            '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      }","sourceCodeStart":1239,"sourceCodeEnd":1275,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/connection_string.ts#L1239-L1275","documentation":"Thrown by the mongodbLogComponentSeverities transform when the value is not an object or is null. This option configures per-component log severity and must be a map of component-name to severity-level strings.","triggerScenarios":"Passing mongodbLogComponentSeverities as a string (e.g. 'command=debug'), an array, a number, null, or undefined-but-coerced. The guard `typeof value !== 'object' || !value` rejects primitives and null.","commonSituations":"Confusing this option's object format with a typical log-level string env var like LOG_LEVEL=debug; passing a JSON-parsed null; copying config from a library that uses a different severity schema.","solutions":["Pass an object: { mongodbLogComponentSeverities: { command: 'debug', default: 'info' } }.","If you only want a global level, use { default: 'debug' }.","Remove the option entirely if you did not intend per-component severities."],"exampleFix":"// before\nnew MongoClient(uri, { mongodbLogComponentSeverities: 'debug' });\n// after\nnew MongoClient(uri, { mongodbLogComponentSeverities: { default: 'debug' } });","handlingStrategy":"type-guard","validationCode":"function isValidComponentSeverities(v) {\n  return v != null && typeof v === 'object' && !Array.isArray(v);\n}","typeGuard":"function isComponentSeverities(v): v is Record<string, string> {\n  return v != null && typeof v === 'object' && !Array.isArray(v);\n}","tryCatchPattern":null,"preventionTips":["Always pass an object map for mongodbLogComponentSeverities.","Use { default: 'info' } as the minimal valid form.","Reject null/undefined/primitives at your config boundary."],"tags":["logging","options","configuration","validation"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}