mongodb/node-mongodb-native · error · MongoCryptError
unidentifiable error in MongoCrypt - received an error statu
Error message
unidentifiable error in MongoCrypt - received an error status from `libmongocrypt` but received no error message.
What it means
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.
Source
Thrown at src/client-side-encryption/state_machine.ts:291
throw new MongoCryptError(message);
}
result = finalizedContext;
break;
}
default:
throw new MongoCryptError(`Unknown state: ${getState()}`);
}
}
if (getState() === MONGOCRYPT_CTX_ERROR || result == null) {
const message = getStatus().message;
if (!message) {
debug(
`unidentifiable error in MongoCrypt - received an error status from \`libmongocrypt\` but received no error message.`
);
}
throw new MongoCryptError(
message ??
'unidentifiable error in MongoCrypt - received an error status from `libmongocrypt` but received no error message.'
);
}
return result;
}
/**
* Handles the request to the KMS service. Exposed for testing purposes. Do not directly invoke.
* @param kmsContext - A C++ KMS context returned from the bindings
* @returns A promise that resolves when the KMS reply has be fully parsed
*/
async kmsRequest(
request: MongoCryptKMSRequest,
options?: { timeoutContext?: TimeoutContext } & Abortable
): Promise<void> {
const parsedUrl = request.endpoint.split(':');View on GitHub (pinned to 3366c21a63)
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.
Example fix
// before: mismatched versions // "mongodb-client-encryption": "^2.x" // after: align with the version matrix in the driver README // "mongodb-client-encryption": "^6.x" (matching driver major)
Defensive patterns
Strategy: try-catch
Type guard
import { MongoCryptError } from 'mongodb';
function isUnidentifiableMongoCryptError(e: unknown): boolean {
return e instanceof MongoCryptError && /unidentifiable error in MongoCrypt/.test(e.message);
} Try / catch
try {
await clientEncryption.createDataKey('aws', { masterKey: { region, key } });
} catch (err) {
if (err instanceof MongoCryptError && /unidentifiable error/.test(err.message)) {
// Likely a version mismatch or malformed data key; enable debug logging and re-run.
process.env.MONGODB_DEBUG = 'true';
}
throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unable to create collection: ${cause.message}
- Malformed JSON body in GET request.
- Unable to complete request.
- Malformed response body - missing field `access_token`.
- Malformed response body - missing field `expires_in`.
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/3930f263f933aa66.json.
Report an issue: GitHub.