mongodb/node-mongodb-native · critical · MongoCryptError

Unknown state: ${getState()}

Error message

Unknown state: ${getState()}

What it means

Defensive default branch in the CSFLE state machine switch — libmongocrypt returned a numeric state value that the driver does not recognise. This indicates a version mismatch: the linked libmongocrypt/crypt_shared introduced a new state constant the driver's bindings do not handle.

Source

Thrown at src/client-side-encryption/state_machine.ts:280

        case MONGOCRYPT_CTX_NEED_KMS: {
          await Promise.all(this.requests(context, options));
          context.finishKMSRequests();
          break;
        }

        case MONGOCRYPT_CTX_READY: {
          const finalizedContext = context.finalize();
          if (getState() === MONGOCRYPT_CTX_ERROR) {
            const message = getStatus().message || 'Finalization error';
            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;
  }

View on GitHub (pinned to dce7939f86)

Solutions

  1. Pin compatible versions of mongodb, mongodb-client-encryption, and libmongocrypt/crypt_shared per the driver's CSFLE compatibility table.
  2. Upgrade the mongodb driver to a release that supports your libmongocrypt/crypt_shared version, or downgrade crypt_shared to match the driver.
  3. If using crypt_shared, ensure the loaded .dll/.so/.dylib is the one shipped with your mongodb-client-encryption build.
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Using a newer crypt_shared/libmongocrypt than the driver supports, or vice versa, exposing an unmapped state integer; a corrupted context object reporting a garbage state value.

Common situations: Upgrading crypt_shared independently of the mongodb driver; using an older driver with a newer libmongocrypt; custom/edge builds of libmongocrypt.

Related errors


AI-assisted analysis of mongodb/node-mongodb-native@dce7939f86 (2026-08-11). Data as JSON: /api/errors/3d31f01356f46aaa. Report an issue: GitHub.