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

  1. Inspect err.parameters.args.writeRow to see the offending row (document, previous state, deleted flags).
  2. 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.
  3. Check that all RxDB plugins and any custom RxStorage are version-matched with the RxDB core version.
  4. If a custom storage is involved, verify its bulkWrite() returns previousDocumentData and deleted flags consistent with the RxStorageInstance contract.
  5. 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

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.