can1357/oh-my-pi · error
Invalid query: empty [] in ${query}
Error message
Invalid query: empty [] in ${query} What it means
parseQuery throws this when a bracket segment contains nothing (or only whitespace) between '[' and ']'. Bracket notation must carry either a numeric index, a quoted key, or a bare token; '[]' and '[ ]' are rejected as meaningless.
Source
Thrown at packages/coding-agent/src/internal-urls/json-query.ts:39
const tokens: Array<string | number> = [];
let i = 0;
const isIdentChar = (ch: string) => /[A-Za-z0-9_-]/.test(ch);
while (i < input.length) {
const ch = input[i];
if (ch === ".") {
i++;
continue;
}
if (ch === "[") {
const closeIndex = input.indexOf("]", i + 1);
if (closeIndex === -1) {
throw new Error(`Invalid query: missing ] in ${query}`);
}
const raw = input.slice(i + 1, closeIndex).trim();
if (!raw) {
throw new Error(`Invalid query: empty [] in ${query}`);
}
const quote = raw[0];
if ((quote === '"' || quote === "'") && raw.endsWith(quote)) {
let inner = raw.slice(1, -1);
inner = inner.replace(/\\(["'\\])/g, "$1");
tokens.push(inner);
} else if (/^\d+$/.test(raw)) {
tokens.push(Number(raw));
} else {
tokens.push(raw);
}
i = closeIndex + 1;
continue;
}
const start = i;
while (i < input.length && isIdentChar(input[i])) {
i++;View on GitHub (pinned to 9690622007)
Solutions
- Put an explicit key or numeric index inside the brackets: '.foo[0]' or '.foo["key"]'.
- If you intended jq-style array iteration, implement a loop over the array in code instead — applyQuery only selects single elements.
- Guard dynamic construction: skip empty segments before appending brackets.
Example fix
// before
const q = `.items[${idx}]`; // idx === ''
// after
const q = idx !== '' ? `.items[${idx}]` : `.items`; Defensive patterns
Strategy: validation
Validate before calling
if (/\[\s*\]/.test(query)) throw new Error(`Empty [] in query: ${query}`); Try / catch
try { tokens = parseQuery(query); } catch (e) { if (String(e.message).includes('empty []')) { /* skip segment or prompt for an index */ } else throw e; } Prevention
- Never use jq's '[]' iteration syntax — this parser selects single elements only.
- Check that interpolated index/key variables are non-empty before building the query.
- Prefer explicit indices from array length checks (idx < arr.length).
When it happens
Trigger: Calling parseQuery/applyQuery with '.foo[]', '.a[ ]', or consecutive brackets like '.foo[][0]'. Also produced by pathToQuery if a path segment somehow collapses to empty after filtering — though normally pathToQuery skips empty segments.
Common situations: Dynamically built queries where a segment variable was empty ('.' + name + '[]' with name=''); template strings whose interpolation produced nothing; users copying jq's '[]' iterate-all syntax which this mini-parser does not support.
Related errors
- Invalid query: missing ] in ${query}
- Invalid query: unexpected token '${input[i]}' in ${query}
- line ${lineNum}: expected a line number such as ${describeAn
- Unsupported language '{value}'. Supported: {}
- Unable to infer language from file extension: {}. Specify `l
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/3e9ebeedd451d814.
Report an issue: GitHub.