SonarSource/sonarqube · error · IllegalStateException
Failed to get repository '%s' on '%s' (this might be related
Error message
Failed to get repository '%s' on '%s' (this might be related to the GitHub App installation scope)
What it means
getRepository fetches a single repository by 'org/repo' identifier. Any exception during the call is wrapped in this IllegalStateException, which explicitly hints that the GitHub App installation scope may not include the repository. It commonly appears when the App is installed but not granted access to the requested repo.
Source
Thrown at server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationClientImpl.java:367
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);
}
}
@Override
public UserAccessToken createUserAccessToken(String appUrl, String clientId, String clientSecret, String code) {
try {
String endpoint = "/login/oauth/access_token?client_id=" + clientId + "&client_secret=" + clientSecret + "&code=" + code;
String baseAppUrl = convertApiUrlToBaseUrl(appUrl);
ApplicationHttpClient.Response response = githubApplicationHttpClient.post(baseAppUrl, null, endpoint);
if (response.getCode() != HTTP_OK) {
if (LOG.isDebugEnabled()) {
LOG.debug("Failed to create GitHub's user access token, response body: {}", response.getContent().orElse(""));
}
throw new IllegalStateException("Failed to create GitHub's user access token. GitHub returned code " + response.getCode() + ".");View on GitHub (pinned to 184c821202)
Solutions
- In GitHub App settings, change Repository access to 'All repositories' or add the target repository to the selection.
- Verify the organizationAndRepository string matches the current 'org/repo' path (repo not renamed).
- Check the token/app permissions include repository metadata (read).
- Confirm the repository still exists and is not archived/private to a different org.
Example fix
// GitHub App settings: Repository access // before: Only select repositories -> [other-repo] // after: All repositories (or add 'my-org/my-repo' to the selection)
Defensive patterns
Strategy: validation
Validate before calling
// check repo path shape before calling
if (organizationAndRepository == null || !organizationAndRepository.matches("[\w.-]+/[\w.-]+")) throw new IllegalArgumentException("Expected 'org/repo', got: " + organizationAndRepository); Try / catch
try { return client.getRepository(url, token, orgRepo); } catch (IllegalStateException e) { log.warn("Repo {} not accessible; check GitHub App installation scope", orgRepo); return Optional.empty(); } Prevention
- Install the GitHub App with 'All repositories' when auto-provisioning
- Re-check installation scope after repos are added
- Detect repo renames via webhooks and update bindings
- Verify the org/repo path exists before linking a project
When it happens
Trigger: Calling getRepository(appUrl, accessToken, organizationAndRepository) when the HTTP call or JSON parsing throws — or when the App installation restricts repository access so the repo endpoint behaves unexpectedly.
Common situations: GitHub App installed with 'Only select repositories' excluding the target repo; repository renamed/deleted; wrong org/repo path; token lacking repo scope.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Failed to check permissions with Github, check the configura
- Failed to list all repositories of '%s' accessible by user a
- Failed to create GitHub's user access token. GitHub returned
- Failed to create the GitHub App from manifest. GitHub return
- Missing permissions; permission granted on %s
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/efa385f671df9cf8.
Report an issue: GitHub.