{"record":{"id":"12ebb3b28d7bd339","repo":"badges/shields","slug":"invalid-response-data","errorCode":null,"errorMessage":"invalid response data","messagePattern":"invalid response data","errorType":"exception","errorClass":"InvalidResponse","httpStatus":424,"severity":"warning","filePath":"services/bitbucket/bitbucket-pipelines.service.js","lineNumber":94,"sourceCode":"          fields: 'values.state',\n          page: 1,\n          pagelen: 2,\n          sort: '-created_on',\n          'target.ref_type': 'BRANCH',\n          'target.ref_name': branch,\n        },\n      },\n      httpErrors: { 403: 'private repo' },\n    })\n  }\n\n  static transform(data) {\n    const values = data.values.filter(\n      value => value.state && value.state.name === 'COMPLETED',\n    )\n    if (values.length > 0) {\n      if (!values[0].state?.result?.name) {\n        throw new InvalidResponse({ prettyMessage: 'invalid response data' })\n      }\n      return values[0].state.result.name\n    }\n    const inProgress = data.values.filter(\n      value => value.state && value.state.name === 'IN_PROGRESS',\n    )\n    if (inProgress.length > 0 && inProgress[0].state?.stage?.name) {\n      // e.g: a pipeline HALTED because the account ran out of build minutes\n      // https://github.com/badges/shields/issues/9096\n      return inProgress[0].state.stage.name.toLowerCase()\n    }\n    return 'never built'\n  }\n\n  async handle({ user, repo, branch }) {\n    const data = await this.fetch({ user, repo, branch })\n    return this.constructor.render({ status: this.constructor.transform(data) })\n  }","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/services/bitbucket/bitbucket-pipelines.service.js#L76-L112","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Check the actual API response for the repository (https://api.bitbucket.org/2.0/repositories/{user}/{repo}/pipelines/) to inspect state.result.","Resolve any HALTED/manual-approval pipelines so they produce a definite result name.","Re-run the pipeline so it completes with a SUCCESSFUL/FAILED result.","Update the library if Bitbucket changed the response schema."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"const data = await fetchPipelines(user, repo)\nconst completed = data.values?.filter(v => v.state?.name === 'COMPLETED') ?? []\nif (completed.length && !completed[0].state?.result?.name) {\n  console.warn('Completed pipeline has no result name — resolve HALTED pipelines')\n}","typeGuard":"function hasResultName(value) {\n  return typeof value?.state?.result?.name === 'string'\n}","tryCatchPattern":"try {\n  return await pipelinesBadge({ user, repo })\n} catch (e) {\n  if (e instanceof InvalidResponse) return renderBadge('unknown')\n  throw e\n}","preventionTips":["Approve or resolve HALTED pipelines so they produce a definite result","Inspect the raw Bitbucket pipelines API response when the badge misbehaves","Keep the library updated for Bitbucket API shape changes"],"tags":["bitbucket","ci","invalid-response","pipelines","api-shape"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}