thedotmack/claude-mem · error

${message}

Error message

${message}

What it means

Not a thrown exception but the worker's standard 400 Bad Request envelope, emitted by BaseRouteHandler.badRequest(res, message). Any route handler that validates input manually calls this helper instead of throwing; the response body is { error: <message> } with no issues array (structured Zod rejections use validateBody instead).

Source

Thrown at src/services/worker/http/BaseRouteHandler.ts:77

      ?? req.get?.('x-claude-mem-platform-source');
    return BaseRouteHandler.firstString(req.query.platformSource)
      ?? BaseRouteHandler.firstString(req.query.platform_source)
      ?? BaseRouteHandler.firstString(body.platformSource)
      ?? BaseRouteHandler.firstString(body.platform_source)
      ?? BaseRouteHandler.firstString(header);
  }

  protected getPlatformSourceFromRequest(req: Request): string {
    return normalizePlatformSource(BaseRouteHandler.rawPlatformSourceFromRequest(req));
  }

  protected getOptionalPlatformSourceFromRequest(req: Request): string | undefined {
    const rawPlatformSource = BaseRouteHandler.rawPlatformSourceFromRequest(req);
    return rawPlatformSource ? normalizePlatformSource(rawPlatformSource) : undefined;
  }

  protected badRequest(res: Response, message: string): void {
    res.status(400).json({ error: message });
  }

  protected notFound(res: Response, message: string): void {
    res.status(404).json({ error: message });
  }

  protected handleError(res: Response, error: Error, context?: string): void {
    const statusCode = error instanceof AppError ? error.statusCode : 500;
    // Client errors (4xx AppErrors) are routine bad input, not server faults, so
    // they log at WARN and are NOT routed to the error sink — surfacing a
    // validation rejection like a bad corpus name as a captured $exception just
    // pollutes error tracking with noise. Only true server faults (5xx, or any
    // non-AppError, which maps to 500) go through logger.failure, whose Error
    // payload routes through logger.error → the error sink → captureException
    // (Phase 3): a REDACTED $exception to PostHog Error Tracking, consent-gated,
    // kill-switch-gated, and rate-limited.
    const isClientError = statusCode >= 400 && statusCode < 500;
    if (isClientError) {

View on GitHub (pinned to e2d1df569a)

Solutions

  1. Read the error string in the 400 body — it states exactly which parameter failed
  2. Compare your payload against the route's Zod schema or handler destructuring in the matching *Routes.ts file
  3. Fix the field name/type in the request and resend

Example fix

// before
await fetch(`${base}/api/sessions/abc/complete`, { method: 'POST' }); // 400 'invalid session id'

// after
const id = Number(rawId);
if (!Number.isInteger(id)) throw new TypeError('session id must be an integer');
await fetch(`${base}/api/sessions/${id}/complete`, { method: 'POST' });
Defensive patterns

Strategy: validation

Validate before calling

function assertSessionId(id: unknown): asserts id is number {
  if (!Number.isInteger(id) || (id as number) <= 0)
    throw new RangeError(`bad session id: ${String(id)}`);
}

Type guard

function isBadRequest(body: unknown): body is { error: string } {
  return typeof body === 'object' && body !== null &&
    typeof (body as { error?: unknown }).error === 'string';
}

Try / catch

const res = await callApi();
if (res.status === 400) {
  const { error } = await res.json();
  throw new InputError(error); // surface the exact field message to the caller/UI
}

Prevention

When it happens

Trigger: Calling a worker API with malformed parameters that the handler checks imperatively: bad session id format, missing query text, invalid pagination, unknown platform source, etc. The exact message comes from the specific route handler.

Common situations: Clients passing undefined/null fields due to destructuring mistakes, wrong units (string vs number), or assuming an older API shape after a worker upgrade changed validation rules.

Related errors


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