can1357/oh-my-pi · error
Invalid query: unexpected token '${input[i]}' in ${query}
Error message
Invalid query: unexpected token '${input[i]}' in ${query} What it means
parseQuery throws this when it encounters a character at the current position that cannot start an identifier (only [A-Za-z0-9_-] are allowed) and is not '.' or '['. The tokenizer has no other production, so any stray character like ':', '/', '"', or '*' outside brackets is rejected with the offending character in the message.
Source
Thrown at packages/coding-agent/src/internal-urls/json-query.ts:60
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++;
}
if (start === i) {
throw new Error(`Invalid query: unexpected token '${input[i]}' in ${query}`);
}
const ident = input.slice(start, i);
tokens.push(ident);
}
return tokens;
}
/**
* Apply a parsed query to a JSON value.
*
* @example
* applyQuery({ foo: { bar: [1, 2, 3] } }, ".foo.bar[0]") // 1
*/
export function applyQuery(data: unknown, query: string): unknown {
const tokens = parseQuery(query);
let current: unknown = data;
for (const token of tokens) {View on GitHub (pinned to 9690622007)
Solutions
- Wrap non-identifier segments in bracket notation: '.["foo/bar"]' or use pathToQuery('/foo/bar') to build a valid query from a path.
- Strip or escape unsupported characters before calling parseQuery.
- If the value came from a URL path, call pathToQuery(urlPath) rather than hand-assembling the query.
Example fix
// before
applyQuery(data, "/foo/bar");
// after
applyQuery(data, pathToQuery("/foo/bar")); // .foo.bar Defensive patterns
Strategy: validation
Validate before calling
if (!/^(\.?[A-Za-z0-9_-]+)(\.[A-Za-z0-9_-]+|\[[^\]]+\])*$/.test(query)) throw new Error(`Query has invalid characters: ${query}`); Try / catch
try { tokens = parseQuery(query); } catch (e) { if (String(e.message).includes('unexpected token')) { query = pathToQuery(query); tokens = parseQuery(query); } else throw e; } Prevention
- Convert URL paths with pathToQuery(), never feed raw paths to parseQuery.
- Wrap any key with characters outside [A-Za-z0-9_-] in ['...'] bracket notation.
- Remember this parser is a jq subset: no pipes, wildcards, or functions.
When it happens
Trigger: Passing a URL-path form like '/foo/bar' directly to parseQuery instead of going through pathToQuery; queries with slashes, colons, spaces, or quotes outside bracket notation, e.g. '.foo/bar' or '.foo bar'.
Common situations: Developers feeding raw path strings ('/data/items') into applyQuery; keys with special characters not wrapped in brackets; copied jq expressions using features (pipes, wildcards, : functions) this subset parser lacks.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Invalid query: missing ] in ${query}
- Invalid query: empty [] 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/10a84da6f3558e43.
Report an issue: GitHub.