{"record":{"id":"3ec923df5b208971","repo":"SonarSource/sonarqube","slug":"failed-to-count-repos-for-alm-setting","errorCode":null,"errorMessage":"Failed to count {} repos for ALM setting '{}'","messagePattern":"Failed to count (.+?) repos for ALM setting '(.+?)'","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/onboarding/alm/OnboardingAlmConfiguration.java","lineNumber":192,"sourceCode":"    }\n\n    protected abstract OptionalLong countRepos(String primary, String pat);\n\n    @Override\n    public OptionalLong fetchTotalCount(OnboardingRows.AlmSetting setting, OnboardingSecretDecryptor decryptor) {\n      String primary = primaryField(setting);\n      String secret = secretField(setting);\n      if (primary == null || secret == null) {\n        return OptionalLong.empty();\n      }\n      try {\n        String pat = decryptor.decrypt(secret);\n        if (pat == null) {\n          return OptionalLong.empty();\n        }\n        return countRepos(primary, pat);\n      } catch (Exception e) {\n        LOG.warn(\"Failed to count {} repos for ALM setting '{}'\", supportedAlm(), setting.key(), e);\n        return OptionalLong.empty();\n      }\n    }\n  }\n\n  private static final class GitlabAlmRepoCountProvider extends PatAlmRepoCountProvider {\n\n    private final GitlabApplicationClient client;\n\n    private GitlabAlmRepoCountProvider(GitlabApplicationClient client) {\n      this.client = client;\n    }\n\n    @Override\n    public String supportedAlm() {\n      return \"gitlab\";\n    }\n","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/api/onboarding/alm/OnboardingAlmConfiguration.java#L174-L210","documentation":"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().","triggerScenarios":"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.","commonSituations":"Rotated or revoked personal access tokens; self-hosted GitLab/Azure URLs unreachable; TLS certificate issues; user lacking permission to list projects/repos.","solutions":["Re-enter/update the PAT for the ALM setting — expired tokens are the most common cause","Check the attached exception for HTTP/auth errors from the provider","Verify network access and TLS trust from SonarQube to the provider URL","Ensure the token's account has permission to enumerate the repos/projects"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"String pat = decryptor.decrypt(secret); if (pat == null || pat.isBlank()) return OptionalLong.empty();","typeGuard":null,"tryCatchPattern":"try { return countRepos(primary, pat); } catch (Exception e) { LOG.warn(\"Failed to count {} repos for ALM setting '{}'\", supportedAlm(), key, e); return OptionalLong.empty(); }","preventionTips":["Keep PATs valid and scoped to repo enumeration","Verify provider URL reachability and TLS trust","Grant the token's account permission to list repos"],"tags":["gitlab","azure-devops","alm","pat"],"backgroundTag":"missing-credentials","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}