{"record":{"id":"097a30bc49bcc70b","repo":"SonarSource/sonarqube","slug":"failed-to-list-all-repositories-of-s-accessible","errorCode":null,"errorMessage":"Failed to list all repositories of '%s' accessible by user access token on '%s' using query '%s'","messagePattern":"Failed to list all repositories of '(.+?)' accessible by user access token on '(.+?)' using query '(.+?)'","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationClientImpl.java","lineNumber":352,"sourceCode":"    try {\n      Repositories repositories = new Repositories();\n      GetResponse response = githubApplicationHttpClient.get(appUrl, accessToken, String.format(\"/search/repositories?q=%s&page=%s&per_page=%s\", searchQuery, page, pageSize));\n      Optional<GsonRepositorySearch> gsonRepositories = response.getContent().map(content -> GSON.fromJson(content, GsonRepositorySearch.class));\n      if (!gsonRepositories.isPresent()) {\n        return repositories;\n      }\n\n      repositories.setTotal(gsonRepositories.get().getTotalCount());\n\n      if (gsonRepositories.get().getItems() != null) {\n        repositories.setRepositories(gsonRepositories.get().getItems().stream()\n          .map(GsonGithubRepository::toRepository)\n          .toList());\n      }\n\n      return repositories;\n    } catch (Exception e) {\n      throw new IllegalStateException(format(\"Failed to list all repositories of '%s' accessible by user access token on '%s' using query '%s'\", organization, appUrl, searchQuery),\n        e);\n    }\n  }\n\n  @Override\n  public Optional<Repository> getRepository(String appUrl, AccessToken accessToken, String organizationAndRepository) {\n    try {\n      GetResponse response = githubApplicationHttpClient.get(appUrl, accessToken, String.format(\"/repos/%s\", organizationAndRepository));\n      return Optional.of(response)\n        .filter(r -> r.getCode() == HTTP_OK)\n        .flatMap(ApplicationHttpClient.Response::getContent)\n        .map(content -> GSON.fromJson(content, GsonGithubRepository.class))\n        .map(GsonGithubRepository::toRepository);\n    } catch (Exception e) {\n      throw new IllegalStateException(format(\"Failed to get repository '%s' on '%s' (this might be related to the GitHub App installation scope)\",\n        organizationAndRepository, appUrl), e);\n    }\n  }","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationClientImpl.java#L334-L370","documentation":"listRepositories searches repositories of an organization accessible by a user access token using a GitHub search query. Any exception during pagination of search results (IOException or other runtime errors) is wrapped in this IllegalStateException naming the organization, appUrl, and query. It indicates the repository listing request failed.","triggerScenarios":"Calling listRepositories(appUrl, accessToken, organization, searchQuery) when the HTTP search exchange or response parsing throws — network failure, malformed query causing an unexpected error, or response body not parseable.","commonSituations":"Invalid search query syntax passed by the project provisioning, network interruption during paginated retrieval, org renamed so results page errors, GHES unreachable.","solutions":["Validate the searchQuery syntax against GitHub's search API (e.g. 'org:my-org in:name').","Check connectivity from the SonarQube server to appUrl.","Confirm the organization name exists and the token has access to it.","Retry the provisioning after any transient GitHub outage; check server logs for the wrapped cause."],"exampleFix":"// before\nclient.listRepositories(url, token, \"my-org\", \"org:my-org language:java is:\"); // malformed\n// after\nclient.listRepositories(url, token, \"my-org\", \"org:my-org language:java\");","handlingStrategy":"validation","validationCode":"// validate query before call\nif (searchQuery == null || !searchQuery.matches(\"[\\\\w\\\\s:@>-]+\")) throw new IllegalArgumentException(\"Invalid GitHub search query: \" + searchQuery);\nif (organization == null || organization.isBlank()) throw new IllegalArgumentException(\"organization required\");","typeGuard":null,"tryCatchPattern":"try { client.listRepositories(url, token, org, query); } catch (IllegalStateException e) { log.error(\"Repo listing failed for org {} query {}\", org, query, e.getCause()); throw e; }","preventionTips":["Test search queries in the GitHub UI/API before wiring them into provisioning","Keep org names in sync when orgs are renamed","Handle pagination failures idempotently so reruns are safe","Log the wrapped cause to distinguish network vs parse errors"],"tags":["github","http","search","alm-binding"],"backgroundTag":"api-request-failed","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}