pubkey/rxdb · error · RxError

SNH

SNH

Error message

RxDB Error-Code: SNH. 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

What it means

SNH is RxDB's 'should not happen' assertion thrown when an internal invariant is violated. In removeConnectedStorageFromCollection it fires when the schema version of the passed RxCollection does not match the version of the schema stored in the database's internal store. This indicates internal bookkeeping is out of sync, usually caused by passing wrong arguments rather than a library bug.

Source

Thrown at src/rx-database-internal-store.ts:343

                },
                'add-connected-storage-to-collection'
            );
        } catch (err) {
            if (!isBulkWriteConflictError(err)) {
                throw err;
            }
            // retry on conflict
        }
    }
}

export async function removeConnectedStorageFromCollection(
    collection: RxCollection<any, unknown, unknown, unknown>,
    storageCollectionName: string,
    schema: RxJsonSchema<any>
) {
    if (collection.schema.version !== schema.version) {
        throw newRxError('SNH', {
            schema,
            version: collection.schema.version,
            name: collection.name,
            collection,
            args: {
                storageCollectionName
            }
        });
    }

    const collectionNameWithVersion = _collectionNamePrimary(collection.name, collection.schema.jsonSchema);
    const collectionDocId = getPrimaryKeyOfInternalDocument(
        collectionNameWithVersion,
        INTERNAL_CONTEXT_COLLECTION
    );

    while (true) {
        const collectionDoc = await getSingleDocument(

View on GitHub (pinned to af6fb65f94)

Solutions

  1. Ensure the schema argument passed is exactly collection.schema.toJSON / the schema the collection was created with (matching version).
  2. Check whether you meant to call this for a different (versioned) collection instance whose version matches the schema.
  3. If this happens after migration, refresh the collection reference (e.g. via db.collections) instead of reusing pre-migration objects.
  4. Use the dev-mode plugin in development to get the full error parameters (schema, versions) for diagnosis.

Example fix

// before
await removeConnectedStorageFromCollection(collection, storageCollectionName, oldSchema);
// after
if (collection.schema.version === oldSchema.version) {
  await removeConnectedStorageFromCollection(collection, storageCollectionName, oldSchema);
} else {
  await removeConnectedStorageFromCollection(collection, storageCollectionName, collection.schema.jsonSchema);
}
Defensive patterns

Strategy: validation

Validate before calling

if (collection.schema.version !== schema.version) {
  throw new Error('schema version mismatch for collection ' + collection.name);
}
await removeConnectedStorageFromCollection(collection, storageCollectionName, schema);

Type guard

function schemaVersionMatches(collection: RxCollection<any>, schema: RxJsonSchema<any>): boolean {
  return collection.schema.version === schema.version;
}

Try / catch

try {
  await removeConnectedStorageFromCollection(collection, storageCollectionName, schema);
} catch (err) {
  if (isRxError(err) && err.code === 'SNH') {
    console.error('Internal store inconsistent: schema version mismatch', collection.name);
  } else {
    throw err;
  }
}

Prevention

When it happens

Trigger: Calling removeConnectedStorageFromCollection(collection, storageCollectionName, schema) with a schema whose version differs from collection.schema.version, e.g. reusing a stale schema object or a schema from a different collection version.

Common situations: Running a schema migration and keeping an old schema reference around; copying example code that passes a hardcoded schema; multiple collection versions (versioned collection names like 'mydata-1') being mixed up.

Related errors


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