SonarSource/sonarqube · warning

Failed to count repos for ALM setting

Error message

Failed to count {} repos for ALM setting '{}'

What it means

PatAlmRepoCountProvider (used for Azure DevOps/GitLab) decrypts the stored PAT and counts repos via the provider API. Failures while counting repos for the ALM setting are logged with the provider type and setting key, returning OptionalLong.empty().

Solutions

  1. Re-enter/update the PAT for the ALM setting — expired tokens are the most common cause
  2. Check the attached exception for HTTP/auth errors from the provider
  3. Verify network access and TLS trust from SonarQube to the provider URL
  4. Ensure the token's account has permission to enumerate the repos/projects
Defensive patterns

Strategy: fallback

Validate before calling

String pat = decryptor.decrypt(secret); if (pat == null || pat.isBlank()) return OptionalLong.empty();

Try / catch

try { return countRepos(primary, pat); } catch (Exception e) { LOG.warn("Failed to count {} repos for ALM setting '{}'", supportedAlm(), key, e); return OptionalLong.empty(); }

Prevention

When it happens

Trigger: In fetchTotalCount: the secret decryptor returns null (count silently skipped) or any Exception occurs during countRepos — bad PAT, unreachable Azure DevOps/GitLab host, API error.

Common situations: Rotated or revoked personal access tokens; self-hosted GitLab/Azure URLs unreachable; TLS certificate issues; user lacking permission to list projects/repos.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/3ec923df5b208971. Report an issue: GitHub.

Appendix: source

Thrown at server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/onboarding/alm/OnboardingAlmConfiguration.java:192

    }

    protected abstract OptionalLong countRepos(String primary, String pat);

    @Override
    public OptionalLong fetchTotalCount(OnboardingRows.AlmSetting setting, OnboardingSecretDecryptor decryptor) {
      String primary = primaryField(setting);
      String secret = secretField(setting);
      if (primary == null || secret == null) {
        return OptionalLong.empty();
      }
      try {
        String pat = decryptor.decrypt(secret);
        if (pat == null) {
          return OptionalLong.empty();
        }
        return countRepos(primary, pat);
      } catch (Exception e) {
        LOG.warn("Failed to count {} repos for ALM setting '{}'", supportedAlm(), setting.key(), e);
        return OptionalLong.empty();
      }
    }
  }

  private static final class GitlabAlmRepoCountProvider extends PatAlmRepoCountProvider {

    private final GitlabApplicationClient client;

    private GitlabAlmRepoCountProvider(GitlabApplicationClient client) {
      this.client = client;
    }

    @Override
    public String supportedAlm() {
      return "gitlab";
    }

View on GitHub (pinned to 184c821202)