nodejs/node · error · HttpError

Unexpected json output

Error message

Unexpected json output: %s

What it means

HttpJSONQuery expects Google pRPC-style endpoints, which prefix their JSON body with the XSSI-protection line `)]}'`. If the first line read is anything else, the server returned non-JSON (HTML error/login page, redirect, proxy interstitial) and the call is failed as HttpError 200 with the offending first line in the message.

Solutions

  1. Confirm the URL is the correct pRPC endpoint.
  2. Re-authenticate / refresh credentials (gcert, luci-auth).
  3. Inspect the actual response body (the %s in the message tells you what came back).
  4. Rule out proxy/interstitial interference.
Defensive patterns

Strategy: try-catch

Try / catch

try:
    data = HttpJSONQuery(url, method='POST', body=body)
except HttpError as e:
    if e.status == 200 and 'Unexpected json output' in str(e):
        # likely an auth/login page or proxy interstitial
        log.error('endpoint did not return JSON; re-auth or check URL: %s', e)
    raise

Prevention

When it happens

Trigger: Querying a buildbucket/monorail-style pRPC endpoint whose response does not begin with the `)]}'` prefix.

Common situations: Endpoint moved/deprecated; auth cookie expired so the server returns an HTML login page; corporate proxy returns an interstitial; wrong host/URL.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/84eba837332086f6. Report an issue: GitHub.

Appendix: source

Thrown at deps/v8/tools/release/roll_bisect.py:85

  response, contents = conn.request(uri=uri, **params)
  contents = contents.decode("utf-8", "replace")
  return StringIO(contents)


def HttpJSONQuery(*args, **params):
  headers = params.setdefault("headers", {})
  headers.setdefault("Accept", "application/json")

  if "body" in params:
    assert (params.get("method", "GET") != "GET")
    if not isinstance(params["body"], str):
      params["body"] = json.dumps(params["body"])
      headers.setdefault("Content-Type", "application/json")

  fh = HttpQuery(*args, **params)
  s = fh.readline()
  if s and s.rstrip() != ")]}'":
    raise HttpError(200, "Unexpected json output: %s" % s)
  s = fh.read()
  if not s:
    return None
  return json.loads(s)


def QueryTryBotsForFailures(change, patchset, timeout=300):
  builds = HttpJSONQuery(
      "https://cr-buildbucket.appspot.com/prpc/buildbucket.v2.Builds/SearchBuilds",
      method="POST",
      body={
          "fields":
              "builds.*.builder,builds.*.id,builds.*.status,builds.*.startTime,builds.*.endTime",
          "predicate": {
              "tags": [{
                  "key": "cq_experimental",
                  "value": "false"
              }],

View on GitHub (pinned to 1b2de5e052)