abhigyanpatwari/GitNexus · error
Query failed
Error message
Query failed
What it means
Fallback HTTP 500 from POST /api/query when executePrepared throws for a reason other than a read-only violation: most often a Cypher syntax error, an undefined variable, or a referenced param key missing from params. Unlike the generic 500s elsewhere, this handler forwards err.message verbatim (falling back to 'Query failed' only when the error has no message), so the response body carries the actual database diagnostic.
Source
Thrown at gitnexus/src/server/api.ts:677
return;
}
const entry = await resolveRepo(requestedRepo(req));
if (!entry) {
res.status(404).json({ error: 'Repository not found' });
return;
}
const lbugPath = path.join(entry.storagePath, 'lbug');
const result = await withLbugDb(lbugPath, () => executePrepared(cypher, queryParams ?? {}), {
readOnly: true,
});
res.json({ result });
} catch (err: any) {
if (isReadOnlyDbError(err)) {
res.status(403).json({ error: 'Write queries are not allowed via the HTTP API' });
return;
}
res.status(500).json({ error: err.message || 'Query failed' });
}
};
/**
* Validate the optional `token` field of POST /api/analyze. Returns an
* { status, error } to send, or null when the token is absent or valid.
*
* The token is a GitHub PAT: charset-restricted (blocks CRLF header
* smuggling), length-bounded (1–256), and bound to github.com using the SAME
* GITHUB_TOKEN_HOSTS allowlist + hostname parse as resolveGitCredential, so a
* token the API accepts is exactly the one buildGitEnv will inject — and one
* it rejects is never sent off github.com.
*
* Exported for unit tests (the route validation is otherwise only reachable
* by booting the server).
*/
export function validateAnalyzeToken(
repoToken: unknown,View on GitHub (pinned to aac7515d2a)
Solutions
- Read the error field in the 500 response body — it contains the underlying Cypher error message and position
- Cross-check every $placeholder against the params object you sent (names and presence)
- Simplify: run MATCH (n) RETURN n LIMIT 1 first to confirm connectivity, then add clauses back one at a time
- If the error smells like storage corruption rather than syntax, re-run gitnexus analyze to rebuild the lbug store
Example fix
// before
const res = await fetch(`${base}/api/query`, { method: 'POST', body: JSON.stringify({ cypher: 'MACH (n) RETRUN n' }) });
console.log(res.status); // 500, message ignored
// after
const res = await fetch(`${base}/api/query`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ cypher }) });
if (!res.ok) {
const { error } = await res.json(); // 'Query failed' path carries the real Cypher diagnostic
showQueryError(error);
} Defensive patterns
Strategy: try-catch
Try / catch
const res = await fetch(`${base}/api/query`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ cypher, params }) });
if (!res.ok) {
const { error } = (await res.json()) as { error?: string };
throw new Error(`cypher failed: ${error ?? res.status}`); // error carries the real engine diagnostic
} Prevention
- Cross-check every $placeholder against the params object before sending
- Smoke-test new queries with MATCH (n) RETURN n LIMIT 1 and grow them clause by clause
- Remember the engine is LadybugDB — Neo4j-specific syntax may not parse
- Re-analyze if errors suggest schema/storage drift
When it happens
Trigger: Typing invalid Cypher ('MACH (n) RETURN n'); referencing $limit in the query but omitting it from params; using labels/relationships that do not exist in this repo's schema (some engines error on unknown tokens); a corrupted lbug store raising an internal error during execution.
Common situations: Iterating on ad-hoc graph queries from a notebook; copying Neo4j-flavored Cypher with syntax the embedded LadybugDB engine does not support; renaming symbols in the query after a re-index changed the schema; params object keys drifted from query placeholders during refactors.
Related errors
- Missing "cypher" in request body
- "params" must be a plain object with scalar values (string/n
- Write queries are not allowed via the HTTP API
- Failed to list repos
- Failed to start analysis
AI-assisted analysis of abhigyanpatwari/GitNexus@aac7515d2a (2026-08-20).
Data as JSON: /api/errors/b7a5e5041d844c82.
Report an issue: GitHub.