{"record":{"id":"b67bc82fe3fa5754","repo":"jackwener/OpenCLI","slug":"sqlite3-failed-on-path-basename-db-e-messag","errorCode":null,"errorMessage":"sqlite3 failed on ${path.basename(db)}: ${e.message}","messagePattern":"sqlite3 failed on (.+?): (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/antigravity/storage.js","lineNumber":49,"sourceCode":"    'Field',\n    'Value',\n];\n\n// ====== Path helpers ======\nconst AG_APP_SUPPORT = path.join(os.homedir(), 'Library/Application Support/Antigravity');\nconst AG_USER_DIR = path.join(AG_APP_SUPPORT, 'User');\nconst AG_GLOBAL_STATE_DB = path.join(AG_USER_DIR, 'globalStorage/state.vscdb');\nconst AG_WORKSPACE_STORAGE = path.join(AG_USER_DIR, 'workspaceStorage');\nconst AG_SETTINGS_JSON = path.join(AG_USER_DIR, 'settings.json');\n\nfunction sqliteQuery(db, sql) {\n    if (!fs.existsSync(db)) {\n        throw new CommandExecutionError(`state.vscdb not found: ${db}`, 'Has Antigravity been run at least once?');\n    }\n    try {\n        return execFileSync('/usr/bin/sqlite3', [db, sql], { encoding: 'utf-8', maxBuffer: 64 * 1024 * 1024 });\n    } catch (e) {\n        throw new CommandExecutionError(\n            `sqlite3 failed on ${path.basename(db)}: ${e.message}`,\n            'The DB may be locked by a running Antigravity instance. Try closing it or wait a few seconds.',\n        );\n    }\n}\nfunction listKeys(db) {\n    const out = sqliteQuery(db, 'SELECT key FROM ItemTable ORDER BY key;');\n    return out.split('\\n').map((s) => s.trim()).filter(Boolean);\n}\nfunction getValue(db, key) {\n    const esc = key.replace(/'/g, \"''\");\n    const raw = sqliteQuery(db, `SELECT value FROM ItemTable WHERE key = '${esc}';`).trim();\n    if (!raw) return null;\n    try { return JSON.parse(raw); } catch { return raw; }\n}\nfunction resolveStateDb(args) {\n    const ws = args?.workspace ? String(args.workspace).trim() : '';\n    if (!ws) return AG_GLOBAL_STATE_DB;","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/antigravity/storage.js#L31-L67","documentation":"sqliteQuery executes /usr/bin/sqlite3 via execFileSync; any failure (non-zero exit, missing binary, spawn error) is wrapped in a CommandExecutionError that includes the sqlite3 stderr/message. The most common cause is the database being locked by the running Antigravity instance, as the hint says.","triggerScenarios":"execFileSync('/usr/bin/sqlite3', [db, sql]) throws: DB locked (SQLITE_BUSY), corrupt DB, sqlite3 binary not installed at /usr/bin/sqlite3, or the SQL is invalid.","commonSituations":"Antigravity is open and holds a write lock on state.vscdb (WAL/journal contention); sqlite3 not installed or installed at a non-standard path (e.g. /usr/local/bin, macOS Homebrew /opt/homebrew); malformed custom SQL passed to raw; corrupted profile after a crash.","solutions":["Close Antigravity (or wait a few seconds) so the DB lock is released, then retry","Copy the db (+ -wal/-shm files) and query the copy to avoid the lock","Install sqlite3 or fix the hardcoded /usr/bin/sqlite3 path (which sqlite3)","Open the DB with 'sqlite3 db \"PRAGMA integrity_check;\"' to rule out corruption","Fix the SQL statement if using the raw command and the message is a syntax error"],"exampleFix":"// before\nsqliteQuery(db, sql) // while Antigravity is running -> SQLITE_BUSY\n// after\ncp state.vscdb /tmp/state-copy.vscdb && cp state.vscdb-wal /tmp/state-copy.vscdb-wal\nsqliteQuery('/tmp/state-copy.vscdb', sql)","handlingStrategy":"retry","validationCode":"const { execFileSync } = require('child_process');\nconst sqlite3Path = ['/usr/bin/sqlite3', '/usr/local/bin/sqlite3'].find(p => fs.existsSync(p));\nif (!sqlite3Path) throw new Error('sqlite3 is not installed');","typeGuard":null,"tryCatchPattern":"async function queryWithRetry(db, sql, attempts = 3) {\n  for (let i = 0; i < attempts; i++) {\n    try { return sqliteQuery(db, sql); }\n    catch (err) {\n      if (!/sqlite3 failed/.test(err.message) || i === attempts - 1) throw err;\n      await new Promise(r => setTimeout(r, 2000 * (i + 1))); // wait out DB lock\n    }\n  }\n}","preventionTips":["Close Antigravity (or query a file copy) to avoid SQLITE_BUSY","Confirm sqlite3 is installed at the expected path","Use the immutable/readonly open flags or a WAL-friendly copy for reads","Run PRAGMA integrity_check if corruption is suspected"],"tags":["sqlite","filesystem","locked-database","antigravity"],"backgroundTag":"database-locked","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}