{"record":{"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/dce7939f86fb283e167ad709955abedb7bf23124/src/connection_string.ts#L1239-L1275","documentation":"`mongodbLogComponentSeverities` maps log components to severity levels. The transform at src/connection_string.ts:1255 requires the value to be a non-null object (`typeof value === 'object' && value`). Passing `null`, a string, a number, an array, or `undefined`-as-other-types triggers MongoAPIError at src/connection_string.ts:1257.","triggerScenarios":"Passing `mongodbLogComponentSeverities: 'debug'` (string); `mongodbLogComponentSeverities: null`; `mongodbLogComponentSeverities: 3` (number); or `mongodbLogComponentSeverities: ['command']` (array).","commonSituations":"Confusing with `mongodbLogPath`/`mongodbLogComponentSeverities` env-var style which takes single strings; providing a single global level instead of a per-component map; JSON config that decodes `null` for missing fields.","solutions":["Pass an object keyed by component: `mongodbLogComponentSeverities: { default: 'info' }`.","Use the dedicated key `default` to set a catch-all severity.","Leave the option unset to rely on environment-derived defaults."],"exampleFix":"// before\nnew MongoClient(uri, { mongodbLogComponentSeverities: 'debug' });\n\n// after\nnew MongoClient(uri, { mongodbLogComponentSeverities: { default: 'debug' } });","handlingStrategy":"type-guard","validationCode":"if (opts.mongodbLogComponentSeverities != null && (typeof opts.mongodbLogComponentSeverities !== 'object' || opts.mongodbLogComponentSeverities === null || Array.isArray(opts.mongodbLogComponentSeverities))) {\n  throw new Error('mongodbLogComponentSeverities must be a non-null object');\n}","typeGuard":"function isComponentSeveritiesMap(v: unknown): v is Record<string, string> { return typeof v === 'object' && v !== null && !Array.isArray(v); }","tryCatchPattern":"try { client = new MongoClient(uri, opts); } catch (e) { if (e instanceof MongoAPIError && /must be a non-null object/.test(e.message)) { opts.mongodbLogComponentSeverities = { default: 'info' }; client = new MongoClient(uri, opts); } else throw e; }","preventionTips":["Always pass an object literal `{ default: 'info' }`.","Reject arrays and primitives at the config boundary.","Use the `default` key for a single catch-all severity."],"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"}