SonarSource/sonarqube · error · IllegalStateException
Failed to list all repositories of '%s' accessible by user a
Error message
Failed to list all repositories of '%s' accessible by user access token on '%s' using query '%s'
What it means
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.
Source
Thrown at server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationClientImpl.java:352
try {
Repositories repositories = new Repositories();
GetResponse response = githubApplicationHttpClient.get(appUrl, accessToken, String.format("/search/repositories?q=%s&page=%s&per_page=%s", searchQuery, page, pageSize));
Optional<GsonRepositorySearch> gsonRepositories = response.getContent().map(content -> GSON.fromJson(content, GsonRepositorySearch.class));
if (!gsonRepositories.isPresent()) {
return repositories;
}
repositories.setTotal(gsonRepositories.get().getTotalCount());
if (gsonRepositories.get().getItems() != null) {
repositories.setRepositories(gsonRepositories.get().getItems().stream()
.map(GsonGithubRepository::toRepository)
.toList());
}
return repositories;
} catch (Exception e) {
throw new IllegalStateException(format("Failed to list all repositories of '%s' accessible by user access token on '%s' using query '%s'", organization, appUrl, searchQuery),
e);
}
}
@Override
public Optional<Repository> getRepository(String appUrl, AccessToken accessToken, String organizationAndRepository) {
try {
GetResponse response = githubApplicationHttpClient.get(appUrl, accessToken, String.format("/repos/%s", organizationAndRepository));
return Optional.of(response)
.filter(r -> r.getCode() == HTTP_OK)
.flatMap(ApplicationHttpClient.Response::getContent)
.map(content -> GSON.fromJson(content, GsonGithubRepository.class))
.map(GsonGithubRepository::toRepository);
} catch (Exception e) {
throw new IllegalStateException(format("Failed to get repository '%s' on '%s' (this might be related to the GitHub App installation scope)",
organizationAndRepository, appUrl), e);
}
}View on GitHub (pinned to 184c821202)
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.
Example fix
// before client.listRepositories(url, token, "my-org", "org:my-org language:java is:"); // malformed // after client.listRepositories(url, token, "my-org", "org:my-org language:java");
Defensive patterns
Strategy: validation
Validate before calling
// validate query before call
if (searchQuery == null || !searchQuery.matches("[\\w\\s:@>-]+")) throw new IllegalArgumentException("Invalid GitHub search query: " + searchQuery);
if (organization == null || organization.isBlank()) throw new IllegalArgumentException("organization required"); Try / catch
try { client.listRepositories(url, token, org, query); } catch (IllegalStateException e) { log.error("Repo listing failed for org {} query {}", org, query, e.getCause()); throw e; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: Invalid search query syntax passed by the project provisioning, network interruption during paginated retrieval, org renamed so results page errors, GHES unreachable.
Understand the failure class
Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.
Related errors
- Failed to check permissions with Github, check the configura
- Failed to get repository '%s' on '%s' (this might be related
- Failed to create GitHub's user access token. GitHub returned
- Failed to create the GitHub App from manifest. GitHub return
- Failed to list all organizations accessible by user access t
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/097a30bc49bcc70b.
Report an issue: GitHub.