badges/shields · warning · InvalidResponse

invalid response data

Error message

invalid response data

What it means

The Bitbucket Pipelines service filters builds for those whose state.name is 'COMPLETED'. If completed builds exist but the first one lacks a state.result.name (e.g. a HALTED or otherwise result-less completion), transform throws InvalidResponse 'invalid response data' because the badge cannot determine pass/fail. This guards against Bitbucket returning unexpected state shapes.

Source

Thrown at services/bitbucket/bitbucket-pipelines.service.js:94

          fields: 'values.state',
          page: 1,
          pagelen: 2,
          sort: '-created_on',
          'target.ref_type': 'BRANCH',
          'target.ref_name': branch,
        },
      },
      httpErrors: { 403: 'private repo' },
    })
  }

  static transform(data) {
    const values = data.values.filter(
      value => value.state && value.state.name === 'COMPLETED',
    )
    if (values.length > 0) {
      if (!values[0].state?.result?.name) {
        throw new InvalidResponse({ prettyMessage: 'invalid response data' })
      }
      return values[0].state.result.name
    }
    const inProgress = data.values.filter(
      value => value.state && value.state.name === 'IN_PROGRESS',
    )
    if (inProgress.length > 0 && inProgress[0].state?.stage?.name) {
      // e.g: a pipeline HALTED because the account ran out of build minutes
      // https://github.com/badges/shields/issues/9096
      return inProgress[0].state.stage.name.toLowerCase()
    }
    return 'never built'
  }

  async handle({ user, repo, branch }) {
    const data = await this.fetch({ user, repo, branch })
    return this.constructor.render({ status: this.constructor.transform(data) })
  }

View on GitHub (pinned to 766fd8bc89)

Solutions

  1. Check the actual API response for the repository (https://api.bitbucket.org/2.0/repositories/{user}/{repo}/pipelines/) to inspect state.result.
  2. Resolve any HALTED/manual-approval pipelines so they produce a definite result name.
  3. Re-run the pipeline so it completes with a SUCCESSFUL/FAILED result.
  4. Update the library if Bitbucket changed the response schema.
Defensive patterns

Strategy: type-guard

Validate before calling

const data = await fetchPipelines(user, repo)
const completed = data.values?.filter(v => v.state?.name === 'COMPLETED') ?? []
if (completed.length && !completed[0].state?.result?.name) {
  console.warn('Completed pipeline has no result name — resolve HALTED pipelines')
}

Type guard

function hasResultName(value) {
  return typeof value?.state?.result?.name === 'string'
}

Try / catch

try {
  return await pipelinesBadge({ user, repo })
} catch (e) {
  if (e instanceof InvalidResponse) return renderBadge('unknown')
  throw e
}

Prevention

When it happens

Trigger: Calling the Bitbucket Pipelines badge when data.values contains a COMPLETED pipeline whose values[0].state.result.name is undefined — Bitbucket API shape change or a pipeline that completed without a recognizable result (e.g. HALTED steps).

Common situations: Bitbucket API response format changes over time; pipelines halted awaiting manual approval that register as COMPLETED without a result name; pipelines with steps skipped or expired; builds created by very old Bitbucket Pipelines versions.

Related errors


AI-assisted analysis of badges/shields@766fd8bc89 (2026-08-30). Data as JSON: /api/errors/12ebb3b28d7bd339. Report an issue: GitHub.