{"record":{"id":"4b0f4100f3bb4496","repo":"badges/shields","slug":"environment-not-found","errorCode":null,"errorMessage":"environment not found","messagePattern":"environment not found","errorType":"exception","errorClass":"NotFound","httpStatus":404,"severity":"error","filePath":"services/github/github-deployments.service.js","lineNumber":121,"sourceCode":"            deployments(last: 1, environments: [$environment]) {\n              nodes {\n                latestStatus {\n                  state\n                }\n              }\n            }\n          }\n        }\n      `,\n      variables: { user, repo, environment },\n      schema,\n      transformErrors,\n    })\n  }\n\n  transform({ data }) {\n    if (data.repository.deployments.nodes.length === 0) {\n      throw new NotFound({ prettyMessage: 'environment not found' })\n    }\n    // This happens for the brief moment a deployment is created, but no\n    // status is created for the deployment (yet).\n    if (data.repository.deployments.nodes[0].latestStatus == null) {\n      return { state: 'NO_STATUS' }\n    }\n\n    const state = data.repository.deployments.nodes[0].latestStatus.state\n    return { state }\n  }\n\n  async handle({ user, repo, environment }) {\n    const json = await this.fetch({ user, repo, environment })\n    const { state } = this.transform({ data: json.data })\n    return this.constructor.render({ state })\n  }\n}\n","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/services/github/github-deployments.service.js#L103-L139","documentation":"The deployments service's transform() throws NotFound 'environment not found' when the GraphQL deployments.nodes array is empty. GitHub returned the repository fine but has zero deployments matching the requested environment, meaning that environment name simply doesn't exist (or has no deployments). This is a 404-style signal about the queried environment.","triggerScenarios":"Requesting a deployment status badge with an `environment` query param (or default) for which the repo has no deployments — e.g. environment=production on a repo that only ever deployed to 'staging'.","commonSituations":"Renamed GitHub Environments (case-sensitive names); badges set up for projects that never used GitHub Environments/deployments; querying an environment from a different repo than intended.","solutions":["Check the repo's Settings > Environments / Actions deployments to get the exact environment name.","Match the environment name's case exactly in the query param.","Create the deployment/environment, or point the badge at an environment that exists."],"exampleFix":"// before\n/service/github/deployments/user/repo.json?environment=Production\n// after (exact name)\n/service/github/deployments/user/repo.json?environment=production","handlingStrategy":"validation","validationCode":"// verify environment name against deployments\nconst deps = await fetch('https://api.github.com/repos/OWNER/REPO/deployments?environment=' + env).then(r => r.json());\nif (!Array.isArray(deps) || deps.length === 0) throw new Error(`environment '${env}' has no deployments`);","typeGuard":"function hasDeployments(data) {\n  return data?.repository?.deployments?.nodes != null && Array.isArray(data.repository.deployments.nodes) && data.repository.deployments.nodes.length > 0;\n}","tryCatchPattern":"try {\n  const state = await getDeploymentStatus({ user, repo, environment });\n} catch (e) {\n  if (e.prettyMessage === 'environment not found') {\n    return { state: 'unknown' }; // or render an inactive badge\n  } else throw e;\n}","preventionTips":["Copy the environment name exactly from Settings > Environments (case-sensitive).","Only add deployment badges to repos that actually use GitHub deployments.","Update badge URLs when renaming environments."],"tags":["github","not-found","deployments","environment"],"backgroundTag":"environment-not-found","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}