{"record":{"id":"bd4c83f7ca19c1e6","repo":"SonarSource/sonarqube","slug":"analysis-s-not-found","errorCode":null,"errorMessage":"Analysis '%s' not found","messagePattern":"Analysis '(.+?)' not found","errorType":"exception","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectanalysis/ws/DeleteAction.java","lineNumber":74,"sourceCode":"      .setSince(\"6.3\")\n      .setPost(true)\n      .setHandler(this);\n\n    action.createParam(PARAM_ANALYSIS)\n      .setDescription(\"Analysis key\")\n      .setExampleValue(Uuids.UUID_EXAMPLE_04)\n      .setRequired(true);\n  }\n\n  @Override\n  public void handle(Request request, Response response) throws Exception {\n    String analysisUuid = request.mandatoryParam(PARAM_ANALYSIS);\n\n    try (DbSession dbSession = dbClient.openSession(false)) {\n      SnapshotDto analysis = dbClient.snapshotDao().selectByUuid(dbSession, analysisUuid)\n        .orElseThrow(() -> analysisNotFoundException(analysisUuid));\n      if (STATUS_UNPROCESSED.equals(analysis.getStatus())) {\n        throw analysisNotFoundException(analysisUuid);\n      }\n      userSession.checkComponentUuidPermission(ProjectPermission.ADMIN, analysis.getRootComponentUuid());\n\n      checkArgument(!analysis.getLast(), \"The last analysis '%s' cannot be deleted\", analysisUuid);\n      checkNotUsedInNewCodePeriod(dbSession, analysis);\n\n      analysis.setStatus(STATUS_UNPROCESSED);\n      dbClient.snapshotDao().update(dbSession, analysis);\n      dbSession.commit();\n    }\n    response.noContent();\n  }\n\n  private void checkNotUsedInNewCodePeriod(DbSession dbSession, SnapshotDto analysis) {\n    boolean isSetAsBaseline = dbClient.newCodePeriodDao().existsByProjectAnalysisUuid(dbSession, analysis.getUuid());\n    checkArgument(!isSetAsBaseline,\n      \"The analysis '%s' can not be deleted because it is set as a new code period baseline\", analysis.getUuid());\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectanalysis/ws/DeleteAction.java#L56-L92","documentation":"api/project_analyses/delete cannot find the requested analysis (snapshot) by uuid, or the snapshot exists but has UNPROCESSED status, which is treated as not-found. DeleteAction.selects the snapshot by uuid and throws analysisNotFoundException('Analysis %s not found') in both cases.","triggerScenarios":"DELETE api/project_analyses/delete with a PARAM_ANALYSIS uuid that does not exist, was already deleted, or refers to an analysis still in UNPROCESSED (in-progress) status.","commonSituations":"Retention scripts replaying a delete for an already-deleted analysis; hardcoded uuid copied from an old log; calling delete while an analysis is still being processed on the compute engine.","solutions":["Re-fetch the analysis uuid via api/project_analyses/search?project=<key> and use a current uuid.","Wait until the analysis finishes processing (status becomes PROCESSED) before deleting.","Make the deletion idempotent: treat 404 as success in cleanup scripts.","Verify you are calling the right SonarQube instance/environment where the analysis exists."],"exampleFix":"// before\ndeleteAnalysis('AXh3kQ9exampleUuid');   // already deleted\n// after\nconst analyses = await get(`/api/project_analyses/search?project=${key}`);\nfor (const a of analyses.analyses) {\n  if (a.status === 'PROCESSED' && !a.last) await deleteAnalysis(a.key);\n}","handlingStrategy":"try-catch","validationCode":"// always resolve a fresh uuid before deleting\nconst search = await get(`/api/project_analyses/search?project=${encodeURIComponent(key)}`);\nconst target = search.analyses.find(a => a.key === analysisUuid);\nif (!target) throw new Error(`Analysis ${analysisUuid} no longer exists`);\nif (target.status !== 'PROCESSED') throw new Error('Analysis still processing; retry later');\nif (target.last) throw new Error('Refusing to delete the last analysis');","typeGuard":"function isDeletableAnalysis(a) {\n  return Boolean(a) && a.status === 'PROCESSED' && a.last === false;\n}","tryCatchPattern":"try {\n  await deleteAnalysis(uuid);\n} catch (e) {\n  if (isNotFound(e, /Analysis .* not found/)) {\n    log.info(`Analysis ${uuid} already gone; treating as deleted`);\n    return;\n  }\n  throw e;\n}","preventionTips":["Make retention scripts idempotent: 404 means already deleted.","Never reuse uuids from old logs; re-list analyses each run.","Skip UNPROCESSED snapshots and the most recent analysis."],"tags":["sonarqube","webapi","project-analysis","not-found"],"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-17T15:17:12.973Z"}