pubkey/rxdb · error · RxError
SNH
SNH
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#SNH
Still stuck? Ask in the RxDB Discord: https://rxdb.info/chat
What it means
SNH stands for 'should not happen' and marks an internal invariant violation. In categorizeBulkWriteRows (src/rx-storage-helper.ts:500), RxDB categorizes each bulk-write row into INSERT, UPDATE or DELETE events. If a successfully written row cannot be classified into one of these three operations, the state is impossible under RxDB's assumptions and SNH is thrown. This is a bug signal, not a validation error: user input that is wrong is normally rejected earlier with a dedicated error code.
Source
Thrown at src/rx-storage-helper.ts:500
let operation: 'INSERT' | 'UPDATE' | 'DELETE';
if (previousDeleted && !documentDeleted) {
operation = 'INSERT';
/**
* Reuse the already-stripped document from updatedRow
* instead of calling stripAttachmentsDataFromDocument() again.
*/
eventDocumentData = hasAttachments ? updatedRow.document : document as any;
} else if (previous && !previousDeleted && !documentDeleted) {
operation = 'UPDATE';
eventDocumentData = hasAttachments ? updatedRow.document : document as any;
previousEventDocumentData = previous;
} else if (documentDeleted) {
operation = 'DELETE';
eventDocumentData = ensureNotFalsy(document) as any;
previousEventDocumentData = previous;
} else {
throw newRxError('SNH', { args: { writeRow } });
}
const event = {
documentId: docId,
documentData: eventDocumentData as RxDocumentData<RxDocType>,
previousDocumentData: previousEventDocumentData,
operation: operation
};
eventBulkEvents.push(event);
}
}
return {
bulkInsertDocs,
bulkUpdateDocs,
newestRow,
errors,
eventBulk,View on GitHub (pinned to af6fb65f94)
Solutions
- Inspect err.parameters.args.writeRow to see the offending row (document, previous state, deleted flags).
- Report it as a bug to RxDB (https://github.com/pubkey/rxdb/issues) including the writeRow parameters, because this branch marks an internal invariant violation.
- Check that all RxDB plugins and any custom RxStorage are version-matched with the RxDB core version.
- If a custom storage is involved, verify its bulkWrite() returns previousDocumentData and deleted flags consistent with the RxStorageInstance contract.
- As a workaround, clear/repair the affected storage data so the inconsistent row state is removed, then retry.
Defensive patterns
Strategy: try-catch
Try / catch
try {
await collection.bulkInsert(docs);
} catch (err) {
if (err && err.code === 'SNH') {
// internal invariant violation: capture state and report as a bug
console.error('RxDB SNH in bulk write, row:', JSON.stringify(err.parameters.args, null, 2));
reportBug(err); // e.g. send to your error tracker
return;
}
throw err;
} Prevention
- Keep RxDB core and all plugins (storages, replication, premium) on matching versions.
- Avoid writing to the same RxStorage instance from multiple processes outside RxDB's conflict handling.
- If you implement a custom RxStorage, test bulkWrite() against the RxDB storage test suite so previousDocument/deleted flags match the contract.
- Treat any SNH occurrence as a bug report trigger, not something to code around.
When it happens
Trigger: A row that passed conflict and validation checks but whose previous document state and deleted flags match none of the three expected combinations (previousDeleted&&!documentDeleted, previous&&!previousDeleted&&!documentDeleted, documentDeleted). In practice: a storage implementation or plugin (custom RxStorage, sharding, replication wrapper) feeding corrupted or inconsistent rows into categorizeBulkWriteRows, or a race where the underlying storage returns inconsistent bulk-write results.
Common situations: Developing or using a third-party RxStorage plugin that returns wrong previousDocument/deleted data from bulkWrite(); using an outdated or incompatible RxStorage/plugin version with a newer RxDB core; concurrent writes from multiple processes bypassing RxDB's conflict handling so the storage returns a state RxDB did not expect.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
AI-assisted analysis of pubkey/rxdb@af6fb65f94 (2026-08-31).
Data as JSON: /api/errors/3c4b0077229f6b65.
Report an issue: GitHub.