pubkey/rxdb · error · RxError

UT6

UT6

Error message

        RxDB Error-Code: ${message}.
        Hint: Error messages are not included in RxDB core to reduce build size.
        To show the full error messages and to ensure that you do not make any mistakes when using RxDB,
        use the dev-mode plugin when you are in development mode: https://rxdb.info/dev-mode.html?console=error
        
Find out more about this error here: https://rxdb.info/errors.html?console=errors#UT6 
Still stuck? Ask in the RxDB Discord: https://rxdb.info/chat 

What it means

UT6 is thrown by ensureRxStorageInstanceParamsAreCorrect (src/rx-storage-helper.ts:877) when the schema contains field-level encryption (a non-empty 'encrypted' array or encryption-enabled fields detected by hasEncryption) but the storage instance is being created for a context where encryption is not allowed. The guard ensures storages that cannot handle encrypted field params fail at creation time with a clear code instead of failing later during writes.

Source

Thrown at src/rx-storage-helper.ts:877

    };

    database.storageInstances.add(ret);
    return ret;
}

/**
 * Each RxStorage implementation should
 * run this method at the first step of createStorageInstance()
 * to ensure that the configuration is correct.
 */
export function ensureRxStorageInstanceParamsAreCorrect(
    params: RxStorageInstanceCreationParams<any, any>
) {
    if (params.schema.keyCompression) {
        throw newRxError('UT5', { args: { params } });
    }
    if (hasEncryption(params.schema)) {
        throw newRxError('UT6', { args: { params } });
    }
    if (
        params.schema.attachments &&
        params.schema.attachments.compression
    ) {
        throw newRxError('UT7', { args: { params } });
    }
}

export function hasEncryption(jsonSchema: RxJsonSchema<any>): boolean {
    if (
        (!!jsonSchema.encrypted && jsonSchema.encrypted.length > 0) ||
        (jsonSchema.attachments && jsonSchema.attachments.encrypted)
    ) {
        return true;
    } else {
        return false;
    }

View on GitHub (pinned to af6fb65f94)

Solutions

  1. Remove the 'encrypted' array from the schema if you do not need field-level encryption.
  2. If you need encryption, register the RxDB encryption plugin and provide the password when creating the database, and create the collection through the normal RxCollection path (not a raw storage instance).
  3. Do not pass an encrypted schema into ensureRxStorageInstanceCreationParams for internal/secondary instances; strip encryption for derived storages.
  4. Check hasEncryption(jsonSchema) yourself before creating a storage instance to detect this configuration early.

Example fix

// before: encrypted fields passed to a plain storage instance
const params = { schema: { ...mySchema, encrypted: ['secret'] }, storage: plainStorage };
ensureRxStorageInstanceParamsAreCorrect(params); // UT6

// after: strip encryption for internal/secondary instances
const params = { schema: { ...mySchema, encrypted: undefined }, storage: plainStorage };
ensureRxStorageInstanceParamsAreCorrect(params);
Defensive patterns

Strategy: validation

Validate before calling

// detect field-level encryption in the schema before creating the instance
function hasEncryption(jsonSchema) {
  return (
    (!!jsonSchema.encrypted && jsonSchema.encrypted.length > 0) ||
    Object.values(jsonSchema.properties || {}).some(p => p.encrypted === true || p.format === 'encrypted')
  );
}

if (hasEncryption(mySchema) && !encryptionPluginRegistered) {
  throw new Error('Encrypted schema requires the encryption plugin and password');
}

Try / catch

try {
  await myRxDatabase.addCollections({ secrets: { schema: encryptedSchema } });
} catch (err) {
  if (err && err.code === 'UT6') {
    console.error('Encryption fields set but storage params disallow encryption');
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: Creating a collection whose RxJsonSchema declares encrypted fields (schema.encrypted array or hasEncryption detection) with a storage configuration that runs this params guard and must not receive encryption settings, e.g. internal storages that create plain instances on top of an encrypted parent collection.

Common situations: Using the encryption plugin fields together with storages or helper paths that create secondary storage instances (replication metastores, migration storage, internal RxDB store) which inherit the schema but must be plain; forgetting that field-level encryption requires the encryption plugin and only applies to the primary collection storage, not derived instances.

Related errors


AI-assisted analysis of pubkey/rxdb@af6fb65f94 (2026-08-31). Data as JSON: /api/errors/30c1bdeb2bc47941. Report an issue: GitHub.