{"record":{"id":"5cb7c62f50db4193","repo":"abhigyanpatwari/GitNexus","slug":"bridge-query-prepare-failed-errmsg","errorCode":null,"errorMessage":"Bridge query prepare failed: ${errMsg}","messagePattern":"Bridge query prepare failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/group/bridge-db.ts","lineNumber":559,"sourceCode":"    } catch (err: unknown) {\n      const msg = err instanceof Error ? err.message : String(err);\n      if (!msg.includes(LBUG_ALREADY_EXISTS_MSG)) throw err;\n    }\n  }\n}\n\nexport async function queryBridge<T>(\n  handle: BridgeHandle,\n  cypher: string,\n  params?: Record<string, LbugValue>,\n): Promise<T[]> {\n  const run = async (): Promise<T[]> => {\n    const conn = handle._conn as lbug.Connection;\n    if (params && Object.keys(params).length > 0) {\n      const stmt = await conn.prepare(cypher);\n      if (!stmt.isSuccess()) {\n        const errMsg = await stmt.getErrorMessage();\n        throw new Error(`Bridge query prepare failed: ${errMsg}`);\n      }\n      const queryResult = await conn.execute(stmt, params);\n      const result = unwrapQueryResult(queryResult);\n      return (await result.getAll()) as T[];\n    }\n    const queryResult = await conn.query(cypher);\n    const result = unwrapQueryResult(queryResult);\n    return (await result.getAll()) as T[];\n  };\n  // Cached RO handles are shared across concurrent @group callers, so serialize\n  // conn ops per handle (a LadybugDB Connection is not safe for concurrent\n  // queries — conn-lock.ts). Uncached/writable handles (the writeBridge temp DB)\n  // are single-threaded — they're absent from bridgeEntryByHandle and skip the\n  // lock at zero cost.\n  const entry = bridgeEntryByHandle.get(handle);\n  return entry ? withHandleLock(entry, run) : run();\n}\n","sourceCodeStart":541,"sourceCodeEnd":577,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/gitnexus/src/core/group/bridge-db.ts#L541-L577","documentation":"Thrown by queryBridge when LadybugDB's conn.prepare(cypher) returns a statement whose isSuccess() is false — i.e. the bridge database rejected the Cypher as syntactically invalid, semantically unsupported, or referencing unknown identifiers. The underlying driver message is appended so the exact LadybugDB parse error is visible. Only the parameterized branch (params present and non-empty) calls prepare(); the no-param branch goes straight to conn.query.","triggerScenarios":"Calling queryBridge(handle, cypher, params) with a Cypher string that LadybugDB cannot compile: syntax errors, misspelled keywords (e.g. MATCHH), unknown node/rel table names from a stale or missing schema (ensureBridgeSchema not run), or a Cypher feature unsupported by the bridge's LadybugDB build.","commonSituations":"Stale bridge DB whose schema lags the query (group synced, contracts changed, but ensureBridgeSchema not re-run against the current BRIDGE_SCHEMA_QUERIES); a typo in a hand-written Cypher literal added during group feature work; a LadybugDB version bump that dropped/renamed a keyword the queries depend on.","solutions":["Read the appended errMsg verbatim — it is LadybugDB's own parse error and pinpoints the offending token.","If the error references an unknown table (NODE TABLE / REL TABLE), ensure ensureBridgeSchema(handle) was run against the current bridge DB before this query.","If the schema is correct, validate the cypher string against the LadybugDB version bundled (check BRIDGE_SCHEMA_QUERIES and the queries module for the exact table/rel names the statement references).","Regenerate the bridge DB (closeBridgeDb + invalidateBridgeCache, then re-run group sync) if the on-disk bridge.lbug predates the current schema."],"exampleFix":"// before — typo'd keyword, prepare() fails\nawait queryBridge(handle, 'MATCHH (n:Symbol) RETURN n', { id });\n\n// after — valid Cypher, prepare() succeeds\nawait queryBridge(handle, 'MATCH (n:Symbol) WHERE n.id = $id RETURN n', { id });","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// queryBridge throws on prepare() failure; catch to fall back or report\ntypealias\ndeclare const _t: never; // placeholder, replace below\n// (see pattern below)\ntry {\n  const rows = await queryBridge<SymbolRow>(handle, cypher, params);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Bridge query prepare failed:')) {\n    logger.error({ cypher, params, msg: err.message }, 'Bridge query rejected');\n    throw err; // prepare errors are not transient — surface, do not retry as-is\n  }\n  throw err;\n}","preventionTips":["Run ensureBridgeSchema(handle) once before issuing queryBridge calls so table names resolve.","Keep the cypher strings in BRIDGE_SCHEMA_QUERIES-aligned modules — don't hand-compose ad-hoc cypher with unverified identifiers.","If you must build cypher dynamically, log it at debug level before calling queryBridge so a prepare failure can be reproduced standalone against the same LadybugDB build."],"tags":["ladybugdb","cypher","group-bridge","query"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}