{"id":"5e0238590ba4939b","repo":"mongodb/node-mongodb-native","slug":"descriptors-missing-a-type-must-define-a-transform","errorCode":null,"errorMessage":"Descriptors missing a type must define a transform","messagePattern":"Descriptors missing a type must define a transform","errorType":"exception","errorClass":"MongoParseError","httpStatus":null,"severity":"info","filePath":"src/connection_string.ts","lineNumber":626,"sourceCode":"        break;\n      }\n      // The value should always be a string here, but since the array is typed as unknown\n      // there still needs to be an explicit cast.\n      // eslint-disable-next-line @typescript-eslint/no-base-to-string\n      mongoOptions[name] = String(values[0]);\n      break;\n    case 'record':\n      if (!isRecord(values[0])) {\n        throw new MongoParseError(`${name} must be an object`);\n      }\n      mongoOptions[name] = values[0];\n      break;\n    case 'any':\n      mongoOptions[name] = values[0];\n      break;\n    default: {\n      if (!transform) {\n        throw new MongoParseError('Descriptors missing a type must define a transform');\n      }\n      const transformValue = transform({ name, options: mongoOptions, values });\n      mongoOptions[name] = transformValue;\n      break;\n    }\n  }\n}\n\ninterface OptionDescriptor {\n  target?: string;\n  type?: 'boolean' | 'int' | 'uint' | 'record' | 'string' | 'any';\n  default?: any;\n\n  deprecated?: boolean | string;\n  /**\n   * @param name - the original option name\n   * @param options - the options so far for resolution\n   * @param values - the possible values in precedence order","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/connection_string.ts#L608-L644","documentation":"Internal invariant violation in the driver's option-processing engine. The OPTIONS descriptor table routes each option through a switch on its declared `type`; the default branch (src/connection_string.ts:624-631) runs only when no recognized `type` is set, and it requires a `transform` function. This error means a descriptor has neither a known `type` nor a `transform`, which is impossible for any built-in option. End users cannot trigger it through normal MongoClientOptions.","triggerScenarios":"Mutating or extending the exported `OPTIONS` object (src/connection_string.ts:649) with a descriptor that omits both `type` and `transform`; a bug in a forked or patched driver version; monkey-patching OPTIONS at runtime. Not reachable from `new MongoClient(uri, options)` with documented options.","commonSituations":"Driver/library developers editing option descriptors; code that spreads custom descriptors into OPTIONS; using an experimental driver branch with incomplete descriptors.","solutions":["Ensure any custom option descriptor sets a valid `type` ('boolean'|'int'|'uint'|'record'|'string'|'any') or supplies a `transform` function","If you are not intentionally extending OPTIONS, file a driver bug with the option name and full stack trace","Stop monkey-patching the exported OPTIONS object; pass options through the documented MongoClientOptions API"],"exampleFix":"// before (broken descriptor)\nOPTIONS.myOpt = { default: 1 };\n// after\nOPTIONS.myOpt = { type: 'uint', default: 1 };\n// or supply a transform\nOPTIONS.myOpt = {\n  transform({ values: [v] }) {\n    return Number(v);\n  }\n};","handlingStrategy":"validation","validationCode":"// Internal invariant: verify any descriptor you add to OPTIONS\nimport { OPTIONS } from 'mongodb'; // illustrative; OPTIONS is internal\nfunction assertDescriptorValid(name, d) {\n  const validTypes = ['boolean','int','uint','record','string','any'];\n  if (!d) throw new Error(`Missing descriptor for ${name}`);\n  if (!validTypes.includes(d.type) && typeof d.transform !== 'function') {\n    throw new Error(`Descriptor ${name} needs a type or transform`);\n  }\n}","typeGuard":"function isValidOptionDescriptor(d) {\n  if (!d || typeof d !== 'object') return false;\n  const validTypes = ['boolean','int','uint','record','string','any'];\n  return validTypes.includes(d.type) || typeof d.transform === 'function';\n}","tryCatchPattern":null,"preventionTips":["Never monkey-patch the exported OPTIONS table at runtime","When extending the driver, always give each descriptor a recognized `type` or a `transform`","Pin to a released driver version rather than a fork with unknown descriptor state"],"tags":["internal","configuration","options"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}