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 ('should not happen') is thrown by removeCollectionDoc when the internal collection document for the given collection name and schema cannot be found in the database's internal store. Removing a collection's internal doc requires that the collection was previously registered; a missing doc means the bookkeeping entry does not exist, so the invariant 'must exist before removal' is violated.
Source
Thrown at src/rx-database.ts:316
return;
}
this.emittedEventBulkIds.add(changeEventBulk.id);
this.eventBulks$.next(changeEventBulk);
}
/**
* removes the collection-doc from the internalStore
*/
async removeCollectionDoc(name: string, schema: any): Promise<void> {
const doc = await getSingleDocument(
this.internalStore,
getPrimaryKeyOfInternalDocument(
_collectionNamePrimary(name, schema),
INTERNAL_CONTEXT_COLLECTION
)
);
if (!doc) {
throw newRxError('SNH', { name, schema });
}
const writeDoc = flatCloneDocWithMeta(doc);
writeDoc._deleted = true;
await this.internalStore.bulkWrite([{
document: writeDoc,
previous: doc
}], 'rx-database-remove-collection');
}
/**
* creates multiple RxCollections at once
* to be much faster by saving db txs and doing stuff in bulk-operations
* This function is not called often, but mostly in the critical path at the initial page load
* So it must be as fast as possible.
*/
async addCollections<CreatedCollections = Partial<Collections>>(collectionCreators: {
[key in keyof CreatedCollections]: RxCollectionCreator<any>View on GitHub (pinned to af6fb65f94)
Solutions
- Only remove collections that currently exist in db.collections (check before calling).
- Ensure the schema passed matches the collection as registered (same name and version).
- Do not call removeCollectionDoc directly; use db.removeCollection(name) which resolves the correct schema.
- If the collection was already removed, treat the operation as done instead of calling removal again.
Example fix
// before
await db.removeCollectionDoc('heroes', schema);
// after
if (db.collections.heroes) {
await db.removeCollection('heroes');
} Defensive patterns
Strategy: validation
Validate before calling
if (!db.collections[name]) {
return;
}
await db.removeCollection(name); Type guard
function collectionExists(db: RxDatabase, name: string): boolean {
return Object.prototype.hasOwnProperty.call(db.collections, name);
} Try / catch
try {
await db.removeCollection(name);
} catch (err) {
if (isRxError(err) && err.code === 'SNH') {
console.warn('Collection internal doc missing; treating as already removed');
} else {
throw err;
}
} Prevention
- Make removal idempotent: check db.collections before removing.
- Never call removeCollectionDoc directly; use the public removeCollection API.
- Avoid removing collections across different RxDatabase instances for the same storage.
When it happens
Trigger: Calling db.removeCollectionDoc(name, schema) (usually internally from db.removeCollection) for a collection whose internal document was never written, was already deleted, or where name/schema do not match the registered collection (e.g. wrong version).
Common situations: Calling removeCollection twice on the same collection; removing a collection in a different database instance than the one that created it; name or schema version mismatch after migrations; corrupted or manually cleared internal store.
Related errors
AI-assisted analysis of pubkey/rxdb@af6fb65f94 (2026-08-31).
Data as JSON: /api/errors/991e55d0830dee36.
Report an issue: GitHub.