{"record":{"id":"5175c092b39d3492","repo":"SonarSource/sonarqube","slug":"no-cache-for-given-branch-or-pull-request","errorCode":null,"errorMessage":"No cache for given branch or pull request","messagePattern":"No cache for given branch or pull request","errorType":"exception","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/scannercache/ws/GetAction.java","lineNumber":96,"sourceCode":"    action.createParam(BRANCH)\n      .setDescription(\"Branch key. If not provided, main branch will be used.\")\n      .setExampleValue(KEY_BRANCH_EXAMPLE_001)\n      .setRequired(false);\n  }\n\n  @Override\n  public void handle(Request request, Response response) throws Exception {\n    String projectKey = request.mandatoryParam(PROJECT);\n    String branchKey = request.param(BRANCH);\n\n    try (DbSession dbSession = dbClient.openSession(false)) {\n      ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey);\n      checkPermission(project);\n      BranchDto branchDto = componentFinder.getBranchOrPullRequest(dbSession, project, branchKey, null);\n\n      try (DbInputStream dbInputStream = cache.get(branchDto.getUuid())) {\n        if (dbInputStream == null) {\n          throw new NotFoundException(\"No cache for given branch or pull request\");\n        }\n\n        boolean compressed = requestedCompressedData(request);\n        try (OutputStream output = response.stream().output()) {\n          if (compressed) {\n            response.setHeader(\"Content-Encoding\", \"gzip\");\n            // data is stored compressed\n            IOUtils.copy(dbInputStream, output);\n          } else {\n            try (InputStream uncompressedInput = new GZIPInputStream(dbInputStream)) {\n              IOUtils.copy(uncompressedInput, output);\n            }\n          }\n        }\n      }\n    }\n  }\n","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/scannercache/ws/GetAction.java#L78-L114","documentation":"ScannerCacheWs GetAction streams the scanner cache for a branch or pull request; when cache.get(branchDto.getUuid()) returns null there is no cached report for that branch/PR, so a NotFoundException is thrown. The branch exists but the compute engine never stored a cache entry for it.","triggerScenarios":"Calling api/analysis_cache/get with branch/pullRequest parameters whose UUID has no entry in the scanner cache table, e.g. before the first analysis completed or after cache eviction.","commonSituations":"Requesting the cache for a brand-new branch that has never been analyzed; CI downloading the cache before the previous analysis finished; cache purged by retention/cleanup jobs; wrong branch name mapping to a fresh branch UUID.","solutions":["Ensure at least one successful analysis of that branch/PR has completed before requesting the cache","Re-check the branch key spelling; a typo may resolve to a different, unanalyzed branch","Retry later if an analysis is still running (the cache is written during report processing)","Handle 404 gracefully in CI: fall back to a full (cold) analysis instead of failing the pipeline"],"exampleFix":"// before\ncurl api/analysis_cache/get?project=my_project&branch=feature-x  # 404 before first analysis\n// after (CI)\nanalyze branch feature-x once; then\ncurl api/analysis_cache/get?project=my_project&branch=feature-x","handlingStrategy":"fallback","validationCode":"// check the branch has been analyzed before fetching cache\nconst branches = await get(`api/project_branches/list?project=${projectKey}`);\nconst b = branches.branches.find(x => x.name === branchKey);\nif (!b || !b.analysisDate) console.warn(\"Branch not analyzed yet; cache will be missing\");","typeGuard":"function isCacheAvailable(branch) {\n  return Boolean(branch && branch.analysisDate);\n}","tryCatchPattern":"try {\n  return await getStream(`api/analysis_cache/get?project=${p}&branch=${b}`);\n} catch (err) {\n  if (err.status === 404 && String(err.message).includes(\"No cache for given branch\")) {\n    return runFullColdAnalysis(); // fallback\n  }\n  throw err;\n}","preventionTips":["Only request the analysis cache after a successful analysis of that branch/PR","In CI, treat a 404 here as 'cold build' rather than a pipeline failure","Verify branch key spelling matches api/project_branches/list output"],"tags":["sonarqube","scanner-cache","not-found","ci"],"backgroundTag":"resource-not-found","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"}