Foundry376/Mailspring · error

Expected '${token}', got '${tok.s}'

Error message

Expected '${token}', got '${tok.s}'

What it means

consumeExpectedToken mismatch: the parser expected a specific grammar token (e.g. a colon after 'from:', or a closing paren) at the current position and found something else. Indicates syntactically malformed user search input such as 'from' with no colon or unbalanced parentheses.

Source

Thrown at app/src/services/search/search-query-parser.ts:186

 * to_query: TO COLON TEXT
 * subject_query: SUBJECT COLON TEXT
 * paren_query: LPAREN query RPAREN
 * is_query: IS COLON is_query_rest
 * is_query_rest: read_cond
 *              | starred_cond
 * has_query: HAS COLON ATTACHMENT
 * read_cond: READ | UNREAD
 * starred_cond: STARRED | UNSTARRED
 * in_query: IN COLON TEXT
 *
 * TEXT: STRING
 *     | [^\s]+
 * STRING: DQUOTE [^"]* DQUOTE
 */
const consumeExpectedToken = (text: string, token: string) => {
  const [tok, afterTok] = nextToken(text);
  if (tok.s !== token) {
    throw new Error(`Expected '${token}', got '${tok.s}'`);
  }
  return afterTok;
};

const parseText = (text: string): [TextQueryExpression, string] => {
  const [tok, afterTok] = nextToken(text);
  if (tok === null) {
    throw new Error('Expected text but none available');
  }
  return [new TextQueryExpression(tok), afterTok];
};

const parseIsQuery = (text: string): [QueryExpression, string] => {
  const afterColon = consumeExpectedToken(text, ':');
  const [tok, afterTok] = nextToken(afterColon);
  if (tok === null) {
    return null;
  }

View on GitHub (pinned to 648c685d60)

Solutions

  1. Add the missing ':' or ')' indicated by the message
  2. Quote search values containing spaces, e.g. from:"John Doe"
  3. Balance all parentheses in the query
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at app/src/services/search/search-query-parser.ts:186 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Foundry376/Mailspring@648c685d60 (2026-09-03). Data as JSON: /api/errors/11a4e4b1aecddf98. Report an issue: GitHub.