{"record":{"id":"ee7feae7a1a23681","repo":"abhigyanpatwari/GitNexus","slug":"ladybugdb-not-initialized-call-initlbug-first","errorCode":null,"errorMessage":"LadybugDB not initialized. Call initLbug first.","messagePattern":"LadybugDB not initialized\\. Call initLbug first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/lbug/lbug-adapter.ts","lineNumber":3195,"sourceCode":" * by files outside the write set — which also means it is never deleted when it\n * SHOULD be, so a destination whose last referrer stopped naming it survived as\n * an edgeless orphan that still carried `address`, the cross-repository join\n * key, accumulating on every run. The mirror defect was worse: without a\n * matching graph-wide re-include, a newly added file publishing to a NEW topic\n * wrote neither the destination nor the publisher's edge, silently and with a\n * zero exit.\n *\n * The `springDestinations` phase runs on every persisting analyze and recomputes\n * the full set from the whole file list, so delete-then-re-include is complete.\n * `extractChangedSubgraph` treats `Destination` as graph-wide to supply the\n * other half; the two must be changed together. DETACH DELETE also takes the\n * `CONSUMES_FROM` / `PUBLISHES_TO` edges, which the re-include restores because\n * every one of them has the destination as an endpoint.\n */\nexport const deleteAllDestinations = async (): Promise<{ nodesDeleted: number }> => {\n  const c = conn;\n  if (!c) {\n    throw new Error('LadybugDB not initialized. Call initLbug first.');\n  }\n  return withConnLock(async () => {\n    let countResult: lbug.QueryResult | lbug.QueryResult[] | undefined;\n    try {\n      countResult = await c.query('MATCH (n:Destination) RETURN count(n) AS cnt');\n      const result = Array.isArray(countResult) ? countResult[0] : countResult;\n      const rows = await result.getAll();\n      const count = Number(rows[0]?.cnt ?? rows[0]?.[0] ?? 0);\n      if (count > 0) {\n        await closeQueryResults(await c.query('MATCH (n:Destination) DETACH DELETE n'));\n      }\n      if (countResult) await closeQueryResults(countResult);\n      return { nodesDeleted: count };\n    } catch (err) {\n      if (countResult) await closeQueryResults(countResult);\n      if (classifyDeleteAllError(err) === 'benign-missing-table') {\n        return { nodesDeleted: 0 };\n      }","sourceCodeStart":3177,"sourceCodeEnd":3213,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/0d1aed942f0e8b5d3bac27519fff441aceea722d/gitnexus/src/core/lbug/lbug-adapter.ts#L3177-L3213","documentation":"deleteAllDestinations requires the module-level LadybugDB connection (conn) to have been established by initLbug. The adapter stores the connection in a module global; every query helper guards on it. Calling any query before initialization means there is no database to run the MATCH delete against, so it throws immediately.","triggerScenarios":"Calling deleteAllDestinations (or any lbug-adapter query helper) before calling initLbug, or after a failed/never-completed initLbug left conn undefined.","commonSituations":"Importing the adapter and calling queries in a script that skips setup; initLbug called in a different process/module instance; an earlier init failure was swallowed so conn never got set.","solutions":["Call await initLbug(...) once at startup before any adapter query.","Guard call sites: if the adapter exposes an initialized/conn accessor, check it before querying.","Ensure initLbug and the queries run in the same process/module instance (same import path).","Check that the initLbug call did not fail earlier — fix the root init error first."],"exampleFix":"// before\nconst { deleteAllDestinations } = await import('./lbug-adapter');\nawait deleteAllDestinations(); // conn undefined\n\n// after\nconst lbug = await import('./lbug-adapter');\nawait lbug.initLbug(dbPath);\nawait lbug.deleteAllDestinations();","handlingStrategy":"try-catch","validationCode":"if (typeof (adapter as { conn?: unknown }).conn === 'undefined') {\n  await adapter.initLbug(dbPath);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await deleteAllDestinations();\n} catch (err) {\n  if (String(err.message).includes('not initialized. Call initLbug')) {\n    await initLbug(dbPath);\n    return deleteAllDestinations();\n  }\n  throw err;\n}","preventionTips":["Initialize the DB in a single startup/bootstrap path before any query.","Centralize init in one module so all importers share the connection.","Fail fast if initLbug rejects — never swallow init errors."],"tags":["initialization","database","ladybugdb","lifecycle"],"backgroundTag":"module-init-failed","analyzedSha":"0d1aed942f0e8b5d3bac27519fff441aceea722d","analyzedAt":"2026-09-08T00:40:44.970Z","contentChangedAt":"2026-09-08T00:40:44.970Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}