thedotmack/claude-mem · error

ValidationError

ValidationError

Error message

ValidationError

What it means

400 ValidationError on POST /v1/events for the query string: EVENT_QUERY_SCHEMA (generate/wait flags) failed zod safeParse of req.query. Only generate and wait are accepted — any other query param, or values other than the literal 'true'/'false' strings these flags parse from, produce issues in the response.

Source

Thrown at src/server/routes/v1/ServerV1PostgresRoutes.ts:247

    // GET /v1/connect — the paste-ready MCP connect command (placeholder key, so
    // a GET never mints). Use POST /v1/keys to get a real read-only key.
    app.get('/v1/connect', readAuth, this.asyncHandler(async (req, res) => {
      const teamId = this.requireTeamId(req, res);
      if (!teamId) return;
      const mcpUrl = mcpConnectUrl(req);
      res.status(200).json({
        mcpUrl,
        connectCommand: mcpConnectCommand(mcpUrl, '<YOUR_API_KEY>'),
        hint: 'POST /v1/keys (write scope) to mint a read-only key for this link.',
      });
    }));

    // POST /v1/events — single event with optional async generation
    app.post('/v1/events', writeAuth, this.asyncHandler(async (req, res) => {
      const parsedQuery = EVENT_QUERY_SCHEMA.safeParse(req.query);
      if (!parsedQuery.success) {
        res.status(400).json({ error: 'ValidationError', issues: parsedQuery.error.issues });
        return;
      }
      const generate = parsedQuery.data.generate !== 'false';
      const wait = parsedQuery.data.wait === 'true';

      const result = CreateAgentEventSchema.safeParse(req.body);
      if (!result.success) {
        res.status(400).json({ error: 'ValidationError', issues: result.error.issues });
        return;
      }
      const body = result.data;
      const teamId = this.requireTeamId(req, res);
      if (!teamId) return;
      if (!this.ensureProjectAllowed(req, res, body.projectId)) return;

      const insertInput = this.toAgentEventInput(body, teamId);
      await this.applyContentSessionLinks([insertInput], [req.body], teamId);
      let event: PostgresAgentEvent;

View on GitHub (pinned to e2d1df569a)

Solutions

  1. Read res.body.issues — zod lists the exact path and expected shape for each bad param.
  2. Use only the literal query strings: generate='true'|'false', wait='true'|'false'.
  3. Drop unrelated query parameters from the URL.
  4. Omit the query string entirely if defaults (generate on, wait off) are acceptable.

Example fix

# before
curl -X POST 'https://host/v1/events?generate=1&wait=yes' -d '{}'
// 400 ValidationError

# after
curl -X POST 'https://host/v1/events?generate=false' -d '{}'
Defensive patterns

Strategy: validation

Validate before calling

const EVENT_QUERY_KEYS = new Set(['generate', 'wait']);
function buildEventQuery(params: Record<string, string> = {}): string {
  const bad = Object.keys(params).filter(k => !EVENT_QUERY_KEYS.has(k));
  if (bad.length) throw new Error(`unsupported query params: ${bad.join(', ')}`);
  for (const v of Object.values(params)) {
    if (v !== 'true' && v !== 'false') throw new Error(`query flags must be 'true'|'false', got ${v}`);
  }
  return new URLSearchParams(params).toString();
}

Type guard

interface ValidationBody { error: string; issues: unknown[] }
function isQueryValidationError(res: Response, body: unknown): body is ValidationBody {
  return res.status === 400 && typeof body === 'object' && body !== null &&
    (body as ValidationBody).error === 'ValidationError';
}

Prevention

When it happens

Trigger: Calling POST /v1/events?generate=1 or ?wait=yes (non-literal values); appending unrelated query params the schema rejects; URL-encoding mistakes that turn the value into something unparseable.

Common situations: Client sends generate=true as a boolean flag helper that serializes to '1'; copy-pasted query params from another API; typos like genrate=true.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of thedotmack/claude-mem@e2d1df569a (2026-08-20). Data as JSON: /api/errors/7cfb5d28ac54d4b2. Report an issue: GitHub.