prometheus/prometheus · warning · Error

missing "error" field in response JSON

Error message

missing "error" field in response JSON

What it means

The codemirror-promql client parsed a JSON body with status:'error' but no 'error' field, violating the Prometheus API response contract. Autocomplete and metadata lookups fail with this placeholder message rather than undefined behavior.

Source

Thrown at web/ui/module/codemirror-promql/src/client/prometheus.ts:233

    this.abortControllers.add(controller);

    if (init) {
      init.headers = this.requestHeaders;
      init.signal = controller.signal;
    } else {
      init = { headers: this.requestHeaders, signal: controller.signal };
    }
    return this.fetchFn(this.url + resource, init)
      .then((res) => {
        if (!res.ok && ![badRequest, unprocessableEntity, serviceUnavailable].includes(res.status)) {
          throw new Error(res.statusText);
        }
        return res;
      })
      .then((res) => res.json())
      .then((apiRes: APIResponse<T>) => {
        if (apiRes.status === 'error') {
          throw new Error(apiRes.error !== undefined ? apiRes.error : 'missing "error" field in response JSON');
        }
        if (apiRes.data === undefined) {
          throw new Error('missing "data" field in response JSON');
        }
        return apiRes.data;
      })
      .finally(() => {
        this.abortControllers.delete(controller);
      });
  }

  private buildRequest(endpoint: string, params: URLSearchParams) {
    let uri = endpoint;
    let body: URLSearchParams | null = params;
    if (this.httpMethod === 'GET') {
      uri = `${uri}?${params}`;
      body = null;
    }

View on GitHub (pinned to 44d6a0e0b1)

Solutions

  1. Inspect the raw response body for the failing editor request.
  2. Point the codemirror-promql client at a real Prometheus endpoint.
  3. Fix proxies/mocks to preserve the full error envelope.
  4. Update mocks in tests to include both status and error fields.
Defensive patterns

Strategy: validation

Validate before calling

const r = await fetch(url);
const body = await r.json();
if (body?.status === 'error' && body.error === undefined) {
  // malformed envelope: log and use a generic message yourself
}

Type guard

function hasErrorField(r: unknown): r is { status: 'error'; error: string } {
  return typeof (r as any)?.error === 'string';
}

Try / catch

catch (err) {
  if (err instanceof Error && err.message.includes('missing "error" field')) {
    // contract violation from intermediary: inspect raw body
  }
}

Prevention

When it happens

Trigger: A response like {"status":"error"} from /api/v1/series, /api/v1/labels, or metadata endpoints used by the editor — usually a rewritten or malformed body from an intermediary.

Common situations: API gateway rewriting error bodies; test mocks missing the error field; a non-Prometheus backend accidentally targeted by the editor client.

Related errors


AI-assisted analysis of prometheus/prometheus@44d6a0e0b1 (2026-08-15). Data as JSON: /api/errors/824d6240ac90a737. Report an issue: GitHub.