koala73/worldmonitor · error · ValidationError

query is required

Error message

query is required

What it means

searchSecFilings throws ValidationError (field 'query') when req.query is empty after trimming — the EDGAR full-text search requires a query string. The check runs before filter validation, so an empty query is reported even if forms/dates are also malformed.

Source

Thrown at server/worldmonitor/intelligence/v1/search-sec-filings.ts:24

import type {
  ServerContext,
  SearchSecFilingsRequest,
  SearchSecFilingsResponse,
} from '../../../../src/generated/server/worldmonitor/intelligence/v1/service_server';
import { ValidationError } from '../../../../src/generated/server/worldmonitor/intelligence/v1/service_server';
import { isEdgarIsoDate, normalizeEdgarForms, searchEdgarFullText } from '../../../_shared/sec-edgar';

const DEFAULT_LIMIT = 10;
const MAX_LIMIT = 25;

export async function searchSecFilings(
  _ctx: ServerContext,
  req: SearchSecFilingsRequest,
): Promise<SearchSecFilingsResponse> {
  const query = req.query?.trim();
  if (!query) {
    throw new ValidationError([{ field: 'query', description: 'query is required' }]);
  }

  // Fail closed on malformed filters. Silently dropping one WIDENS the result
  // set, so a typo'd date range would return unrelated filings while the caller
  // believes the range was applied.
  const formsNormalized = normalizeEdgarForms(req.forms);
  const startDateValid = !req.startDate || isEdgarIsoDate(req.startDate);
  const endDateValid = !req.endDate || isEdgarIsoDate(req.endDate);
  const violations = [
    ...(formsNormalized === null
      ? [{ field: 'forms', description: 'forms must be a comma-separated form list such as "8-K" or "10-K,10-Q"' }]
      : []),
    ...(!startDateValid
      ? [{ field: 'start_date', description: 'start_date must be YYYY-MM-DD' }]
      : []),
    ...(!endDateValid
      ? [{ field: 'end_date', description: 'end_date must be YYYY-MM-DD' }]
      : []),

View on GitHub (pinned to eeab0a219f)

Solutions

  1. Require a non-blank query in the client before calling
  2. Skip iteration when the search term is empty instead of calling the API
  3. Verify the request body uses the exact proto field name 'query'
Defensive patterns

Strategy: validation

Validate before calling

const query = rawQuery?.trim();
if (!query) {
  throw new ClientError('A search query is required');
}

Type guard

function isQueryViolation(body: unknown): boolean {
  const v = (body as { violations?: { field?: string }[] })?.violations;
  return Array.isArray(v) && v.some((x) => x.field === 'query');
}

Try / catch

try {
  await searchSecFilings({ query });
} catch (e) {
  if (e instanceof HttpError && e.status === 400 && isQueryViolation(e.body)) {
    return focusSearchBox();
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling /api/intelligence/v1/search-sec-filings with query omitted or whitespace; a search box submitted empty; programmatic calls where the query variable failed to populate (undefined coerced to '').

Common situations: Missing client-side required-field validation; script iterating search terms where one iteration's term is blank; parameter sent under a different name (q vs query) leaving query empty.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of koala73/worldmonitor@eeab0a219f (2026-08-21). Data as JSON: /api/errors/4986cca5346f554f. Report an issue: GitHub.