{"record":{"id":"b88239f90f86d8ae","repo":"pubkey/rxdb","slug":"snh","errorCode":"SNH","errorMessage":"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","messagePattern":"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","errorType":"error_code","errorClass":"RxError","httpStatus":null,"severity":"error","filePath":"src/rx-database-internal-store.ts","lineNumber":343,"sourceCode":"                },\n                'add-connected-storage-to-collection'\n            );\n        } catch (err) {\n            if (!isBulkWriteConflictError(err)) {\n                throw err;\n            }\n            // retry on conflict\n        }\n    }\n}\n\nexport async function removeConnectedStorageFromCollection(\n    collection: RxCollection<any, unknown, unknown, unknown>,\n    storageCollectionName: string,\n    schema: RxJsonSchema<any>\n) {\n    if (collection.schema.version !== schema.version) {\n        throw newRxError('SNH', {\n            schema,\n            version: collection.schema.version,\n            name: collection.name,\n            collection,\n            args: {\n                storageCollectionName\n            }\n        });\n    }\n\n    const collectionNameWithVersion = _collectionNamePrimary(collection.name, collection.schema.jsonSchema);\n    const collectionDocId = getPrimaryKeyOfInternalDocument(\n        collectionNameWithVersion,\n        INTERNAL_CONTEXT_COLLECTION\n    );\n\n    while (true) {\n        const collectionDoc = await getSingleDocument(","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/pubkey/rxdb/blob/af6fb65f94cd70558d74c23799eda11ff1c15224/src/rx-database-internal-store.ts#L325-L361","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the schema argument passed is exactly collection.schema.toJSON / the schema the collection was created with (matching version).","Check whether you meant to call this for a different (versioned) collection instance whose version matches the schema.","If this happens after migration, refresh the collection reference (e.g. via db.collections) instead of reusing pre-migration objects.","Use the dev-mode plugin in development to get the full error parameters (schema, versions) for diagnosis."],"exampleFix":"// before\nawait removeConnectedStorageFromCollection(collection, storageCollectionName, oldSchema);\n// after\nif (collection.schema.version === oldSchema.version) {\n  await removeConnectedStorageFromCollection(collection, storageCollectionName, oldSchema);\n} else {\n  await removeConnectedStorageFromCollection(collection, storageCollectionName, collection.schema.jsonSchema);\n}","handlingStrategy":"validation","validationCode":"if (collection.schema.version !== schema.version) {\n  throw new Error('schema version mismatch for collection ' + collection.name);\n}\nawait removeConnectedStorageFromCollection(collection, storageCollectionName, schema);","typeGuard":"function schemaVersionMatches(collection: RxCollection<any>, schema: RxJsonSchema<any>): boolean {\n  return collection.schema.version === schema.version;\n}","tryCatchPattern":"try {\n  await removeConnectedStorageFromCollection(collection, storageCollectionName, schema);\n} catch (err) {\n  if (isRxError(err) && err.code === 'SNH') {\n    console.error('Internal store inconsistent: schema version mismatch', collection.name);\n  } else {\n    throw err;\n  }\n}","preventionTips":["Always derive the schema argument from the collection itself, never from stale references.","Let db.removeCollection() handle internal doc removal instead of calling internal helpers.","Use the dev-mode plugin so SNH errors include full parameters.","After migrations, re-fetch collections from db.collections instead of caching old instances."],"tags":["internal-state","schema-version","assertion"],"backgroundTag":"internal-invariant-violated","analyzedSha":"af6fb65f94cd70558d74c23799eda11ff1c15224","analyzedAt":"2026-08-31T23:32:37.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}