{"id":"3930f263f933aa66","repo":"mongodb/node-mongodb-native","slug":"unidentifiable-error-in-mongocrypt-received-an-e","errorCode":null,"errorMessage":"unidentifiable error in MongoCrypt - received an error status from `libmongocrypt` but received no error message.","messagePattern":"unidentifiable error in MongoCrypt - received an error status from `libmongocrypt` but received no error message\\.","errorType":"exception","errorClass":"MongoCryptError","httpStatus":null,"severity":"error","filePath":"src/client-side-encryption/state_machine.ts","lineNumber":291,"sourceCode":"            throw new MongoCryptError(message);\n          }\n          result = finalizedContext;\n          break;\n        }\n\n        default:\n          throw new MongoCryptError(`Unknown state: ${getState()}`);\n      }\n    }\n\n    if (getState() === MONGOCRYPT_CTX_ERROR || result == null) {\n      const message = getStatus().message;\n      if (!message) {\n        debug(\n          `unidentifiable error in MongoCrypt - received an error status from \\`libmongocrypt\\` but received no error message.`\n        );\n      }\n      throw new MongoCryptError(\n        message ??\n          'unidentifiable error in MongoCrypt - received an error status from `libmongocrypt` but received no error message.'\n      );\n    }\n\n    return result;\n  }\n\n  /**\n   * Handles the request to the KMS service. Exposed for testing purposes. Do not directly invoke.\n   * @param kmsContext - A C++ KMS context returned from the bindings\n   * @returns A promise that resolves when the KMS reply has be fully parsed\n   */\n  async kmsRequest(\n    request: MongoCryptKMSRequest,\n    options?: { timeoutContext?: TimeoutContext } & Abortable\n  ): Promise<void> {\n    const parsedUrl = request.endpoint.split(':');","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/client-side-encryption/state_machine.ts#L273-L309","documentation":"Thrown by the libmongocrypt state machine when the native context enters the MONGOCRYPT_CTX_ERROR state but getStatus().message is empty. The driver has no human-readable text from libmongocrypt to relay, so it reports this generic fallback. It almost always indicates a bug in libmongocrypt, a version skew between mongodb-client-encryption and libmongocrypt, or a malformed KMS/data-key document that libmongocrypt rejected without setting an error string.","triggerScenarios":"In state_machine.ts execute() after the state loop ends in MONGOCRYPT_CTX_ERROR with no status message; can occur during createContext()/createDataKey()/encrypt()/decrypt() of CSFLE/ClientEncryption.","commonSituations":"Incompatible versions of mongodb-client-encryption native bindings and libmongocrypt; corrupted or schema-malformed data key documents; KMS provider object with unexpected fields; calling ClientEncryption APIs after the parent context was disposed; rare libmongocrypt bug where an error path didn't populate the message.","solutions":["Update mongodb-client-encryption (and thereby libmongocrypt) to the latest version compatible with this driver version.","Enable driver logging (MONGODB_DEBUG=true or set logger) to capture libmongocrypt status traces before the empty-message error.","Inspect the data key document(s) in the key vault collection for malformed fields, missing keyMaterial, or invalid masterKey.","Reproduce with a minimal CSFLE snippet and file a bug with the driver / mongodb-client-encryption including versions and the operation invoked."],"exampleFix":"// before: mismatched versions\n// \"mongodb-client-encryption\": \"^2.x\"\n\n// after: align with the version matrix in the driver README\n// \"mongodb-client-encryption\": \"^6.x\"  (matching driver major)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"import { MongoCryptError } from 'mongodb';\nfunction isUnidentifiableMongoCryptError(e: unknown): boolean {\n  return e instanceof MongoCryptError && /unidentifiable error in MongoCrypt/.test(e.message);\n}","tryCatchPattern":"try {\n  await clientEncryption.createDataKey('aws', { masterKey: { region, key } });\n} catch (err) {\n  if (err instanceof MongoCryptError && /unidentifiable error/.test(err.message)) {\n    // Likely a version mismatch or malformed data key; enable debug logging and re-run.\n    process.env.MONGODB_DEBUG = 'true';\n  }\n  throw err;\n}","preventionTips":["Pin mongodb-client-encryption to a version compatible with the driver (see driver README matrix).","Never hand-edit data key documents in the key vault collection.","Enable driver logging when diagnosing CSFLE failures."],"tags":["csfle","libmongocrypt","queryable-encryption","native-bindings"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}