{"record":{"id":"c9db131f41973817","repo":"decolua/9router","slug":"db-bun-sqlite-unavailable-e-message","errorCode":null,"errorMessage":"[DB] bun:sqlite unavailable: ${e.message}","messagePattern":"\\[DB\\] bun:sqlite unavailable: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/lib/db/driver.js","lineNumber":14,"sourceCode":"import { ensureDirs, DATA_FILE } from \"./paths.js\";\n\n// Use global to survive Next.js dev hot-reload (module state resets on reload)\nif (!global._dbAdapter) global._dbAdapter = { instance: null, initPromise: null, logged: false };\nconst state = global._dbAdapter;\n\nasync function tryBunSqlite() {\n  // Bun runtime only — built-in, no install needed\n  if (!process.versions.bun) return null;\n  try {\n    const { createBunSqliteAdapter } = await import(\"./adapters/bunSqliteAdapter.js\");\n    return await createBunSqliteAdapter(DATA_FILE);\n  } catch (e) {\n    console.warn(`[DB] bun:sqlite unavailable: ${e.message}`);\n    return null;\n  }\n}\n\nasync function tryBetterSqlite() {\n  // Skip on Bun — better-sqlite3 native bindings unsupported\n  if (process.versions.bun) return null;\n  try {\n    const { createBetterSqliteAdapter } = await import(\"./adapters/betterSqliteAdapter.js\");\n    return createBetterSqliteAdapter(DATA_FILE);\n  } catch (e) {\n    console.warn(`[DB] better-sqlite3 unavailable: ${e.message}`);\n    return null;\n  }\n}\n\nasync function tryNodeSqlite() {\n  // Built-in since Node 22.5.0 — no install needed. Skip under Bun (no node:sqlite).","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/src/lib/db/driver.js#L1-L32","documentation":"First link in the SQLite driver fallback chain (src/lib/db/driver.js). tryBunSqlite only runs under the Bun runtime; if the built-in bun:sqlite adapter fails to import or initialize against DATA_FILE, it logs this warning and returns null so initAdapter falls through to better-sqlite3 / node:sqlite / sql.js. It is informational unless every driver in the chain fails.","triggerScenarios":"Running under Bun while createBunSqliteAdapter throws: the dynamic import of ./adapters/bunSqliteAdapter.js fails, the DB file path is invalid/locked, or the database file is corrupt.","commonSituations":"Bun version with a broken or restricted bun:sqlite; DATA_FILE in an unwritable directory; corrupted existing 9router.db; bundled/packaged environment where the adapter file is missing.","solutions":["Check the logged e.message for the real cause (import failure vs file open error).","Verify DATA_FILE's directory exists and is writable.","Update Bun to a recent version (bun:sqlite is built-in and mature in current releases).","If under Bun anyway, let the chain fall through — sql.js will be used; no action needed unless all drivers fail."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Confirm which driver will be used at startup\nif (process.versions.bun) console.log(\"Bun runtime — bun:sqlite expected\");","typeGuard":null,"tryCatchPattern":"try {\n  const adapter = await getAdapter();\n  console.log(\"DB ready with driver:\", adapter.driver);\n} catch (e) {\n  if (e.message.includes(\"No SQLite driver\")) console.error(\"All SQLite drivers failed — check disk and install\");\n}","preventionTips":["Keep Bun up to date; bun:sqlite is built into current releases.","Log the chosen adapter.driver at startup and alert on unexpected fallbacks.","Ensure the data directory is writable so the driver can open DATA_FILE.","Don't treat this warning as fatal — the chain falls through to sql.js."],"tags":["sqlite","bun","driver-fallback","database"],"backgroundTag":"sqlite-driver-unavailable","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}