badges/shields · error · NotFound

environment not found

Error message

environment not found

What it means

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.

Source

Thrown at services/github/github-deployments.service.js:121

            deployments(last: 1, environments: [$environment]) {
              nodes {
                latestStatus {
                  state
                }
              }
            }
          }
        }
      `,
      variables: { user, repo, environment },
      schema,
      transformErrors,
    })
  }

  transform({ data }) {
    if (data.repository.deployments.nodes.length === 0) {
      throw new NotFound({ prettyMessage: 'environment not found' })
    }
    // This happens for the brief moment a deployment is created, but no
    // status is created for the deployment (yet).
    if (data.repository.deployments.nodes[0].latestStatus == null) {
      return { state: 'NO_STATUS' }
    }

    const state = data.repository.deployments.nodes[0].latestStatus.state
    return { state }
  }

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

View on GitHub (pinned to 766fd8bc89)

Solutions

  1. Check the repo's Settings > Environments / Actions deployments to get the exact environment name.
  2. Match the environment name's case exactly in the query param.
  3. Create the deployment/environment, or point the badge at an environment that exists.

Example fix

// before
/service/github/deployments/user/repo.json?environment=Production
// after (exact name)
/service/github/deployments/user/repo.json?environment=production
Defensive patterns

Strategy: validation

Validate before calling

// verify environment name against deployments
const deps = await fetch('https://api.github.com/repos/OWNER/REPO/deployments?environment=' + env).then(r => r.json());
if (!Array.isArray(deps) || deps.length === 0) throw new Error(`environment '${env}' has no deployments`);

Type guard

function hasDeployments(data) {
  return data?.repository?.deployments?.nodes != null && Array.isArray(data.repository.deployments.nodes) && data.repository.deployments.nodes.length > 0;
}

Try / catch

try {
  const state = await getDeploymentStatus({ user, repo, environment });
} catch (e) {
  if (e.prettyMessage === 'environment not found') {
    return { state: 'unknown' }; // or render an inactive badge
  } else throw e;
}

Prevention

When it happens

Trigger: 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'.

Common situations: 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.

Related errors


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