{"record":{"id":"615a68a29d9089c1","repo":"can1357/oh-my-pi","slug":"deltasync-requires-a-memory-object-with-conn-or-db","errorCode":null,"errorMessage":"DeltaSync requires a memory object with conn or db","messagePattern":"DeltaSync requires a memory object with conn or db","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/mnemopi/src/core/streaming.ts","lineNumber":283,"sourceCode":"\t\t};\n\t}\n\ttoJson(): string {\n\t\treturn JSON.stringify(this.toDict());\n\t}\n\tstatic fromJSON(text: string): SyncCheckpoint {\n\t\treturn new SyncCheckpoint(JSON.parse(text) as SyncCheckpointInit);\n\t}\n}\n\ntype MemoryHost = {\n\treadonly conn?: Database;\n\treadonly db?: Database;\n\treadonly dbPath?: string;\n\treadonly db_path?: string;\n};\nfunction databaseOf(host: MemoryHost): Database {\n\tconst db = host.conn ?? host.db;\n\tif (db === undefined) throw new TypeError(\"DeltaSync requires a memory object with conn or db\");\n\treturn db;\n}\nfunction assertDeltaTable(table: unknown): asserts table is DeltaTable {\n\tif (typeof table !== \"string\" || !ALLOWED_DELTA_TABLES.has(table as DeltaTable))\n\t\tthrow new RangeError(`Delta table ${String(table)} is not in the allowlist`);\n}\nfunction checkpointRoot(host: MemoryHost): string {\n\tconst path = host.dbPath ?? host.db_path;\n\treturn path === undefined || path === \":memory:\"\n\t\t? join(process.cwd(), \".mnemopi-sync\")\n\t\t: join(path, \"..\", \"sync_checkpoints\");\n}\n\nexport class DeltaSync {\n\treadonly checkpointDir: string;\n\tprivate readonly db: Database;\n\tconstructor(\n\t\treadonly mnemopi: MemoryHost,","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/mnemopi/src/core/streaming.ts#L265-L301","documentation":"DeltaSync needs a SQLite connection to read/write sync state, and it obtains one from the memory host object's conn or db property. If the host object passed to the DeltaSync constructor has neither (or they are undefined), databaseOf throws this TypeError so sync is never attempted against a missing database.","triggerScenarios":"new DeltaSync(memory) where memory is a plain object/DTO without conn or db; passing a config/options object instead of the memory instance; a memory object whose connection was closed and set to undefined; forgetting to open the database before constructing DeltaSync.","commonSituations":"Passing deserialized JSON of a memory (connection handle doesn't survive serialization); partially initialized memory objects during app startup; wiring mistakes where a settings object is passed instead of the memory; using an in-memory-only store that never had a Database attached.","solutions":["Ensure the object passed to DeltaSync has an open Database on conn or db (e.g. memory.conn = new Database(path))","Pass the actual memory host instance, not a plain/config object","Open the database before constructing DeltaSync and keep the reference alive"],"exampleFix":"// before\nconst sync = new DeltaSync({ id: \"m1\" });\n// after\nconst memory = { id: \"m1\", conn: new Database(\"./memories.db\") };\nconst sync = new DeltaSync(memory);","handlingStrategy":"type-guard","validationCode":"function assertMemoryHost(host) {\n\tif (host == null || (host.conn === undefined && host.db === undefined)) {\n\t\tthrow new TypeError(\"DeltaSync host must expose an open Database on conn or db\");\n\t}\n}","typeGuard":"function isMemoryHost(host) {\n\treturn host != null && (host.conn !== undefined || host.db !== undefined);\n}","tryCatchPattern":"try {\n\tconst sync = new DeltaSync(memory);\n} catch (err) {\n\tif (err instanceof TypeError && err.message.includes(\"conn or db\")) {\n\t\tthrow new Error(\"Open the memory database before constructing DeltaSync\", { cause: err });\n\t}\n\tthrow err;\n}","preventionTips":["Open the database before constructing DeltaSync","Pass the memory host instance, never a plain config/DTO object","Don't serialize/deserialize objects carrying live Database handles","Attach conn immediately after creating a memory object"],"tags":["database","initialization","missing-argument"],"backgroundTag":"missing-database-connection","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}