cli/cli · error

error fetching organization teams: %w

Error message

error fetching organization teams: %w

What it means

RepoMetadata fetches organization teams in parallel when Reviewers and TeamReviewers inputs are set. OrganizationTeams is called and any error whose message does NOT contain errorResolvingOrganization (i.e. the repo genuinely belongs to an org but the query failed) is wrapped with this message and fails the errgroup. Non-org repos are tolerated: the 'Could not resolve to an Organization' error is swallowed so team review is silently skipped for personal repos.

Source

Thrown at api/queries_repo.go:1027

		} else {
			// Not using Actors, fetch legacy assignable users.
			g.Go(func() error {
				users, err := RepoAssignableUsers(client, repo)
				if err != nil {
					err = fmt.Errorf("error fetching assignable users: %w", err)
				}
				result.AssignableUsers = users
				return err
			})
		}
	}

	if input.Reviewers && input.TeamReviewers {
		g.Go(func() error {
			teams, err := OrganizationTeams(client, repo)
			// TODO: better detection of non-org repos
			if err != nil && !strings.Contains(err.Error(), errorResolvingOrganization) {
				err = fmt.Errorf("error fetching organization teams: %w", err)
				return err
			}
			result.Teams = teams
			return nil
		})
	}

	if input.Reviewers {
		g.Go(func() error {
			login, err := CurrentLoginName(client, repo.RepoHost())
			if err != nil {
				err = fmt.Errorf("error fetching current login: %w", err)
			}
			result.CurrentLogin = login
			return err
		})
	}

View on GitHub (pinned to 0eeec0b92e)

Solutions

  1. Authorize the token for SAML SSO: 'gh auth refresh -h github.com -s read:org' (or click Authorize on the org SSO page)
  2. If using a GitHub App token, grant it read access to org teams or reinstall with permissions
  3. Verify org allows your OAuth app access under org settings -> Third-party Access
  4. Check network/proxy reachability of the API host

Example fix

# before (token not SSO-authorized)
gh pr create --reviewer @acme/core --fill
# -> error fetching organization teams: ...

# after
gh auth refresh -h github.com -s read:org
# complete SSO authorization in browser, then
gh pr create --reviewer @acme/core --fill
Defensive patterns

Strategy: validation

Validate before calling

// Skip team reviewers when the repo has no org, avoiding the query entirely
if !isOrgRepo(repo) {
    input.TeamReviewers = false
}

Try / catch

if err != nil {
    if strings.Contains(err.Error(), "organization teams") && isSamlError(err) {
        return fmt.Errorf("authorize this token for SAML SSO on the org, then retry: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: 'gh pr create --reviewer @org/team-slug' on an org-owned repo when the organization teams GraphQL query fails: insufficient org token permissions (org read blocked by SSO), org enforcing OAuth app restrictions, or network failure. Not triggered for user-owned repos because the resolving-organization error is filtered.

Common situations: SAML SSO not authorized for the token on the org; GitHub App installations lacking org member/team read; org owners restricting third-party access; typos in team slug are NOT this error (that is a later not-found error).

Related errors


AI-assisted analysis of cli/cli@0eeec0b92e (2026-08-15). Data as JSON: /api/errors/4588f12bef9ed139. Report an issue: GitHub.