{"record":{"id":"be5137bfaae566f7","repo":"SonarSource/sonarqube","slug":"analysis-export-failed-after-processing-d-analyse","errorCode":null,"errorMessage":"Analysis Export failed after processing %d analyses successfully","messagePattern":"Analysis Export failed after processing (.+?) analyses successfully","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"critical","filePath":"server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStep.java","lineNumber":89,"sourceCode":"    long count = 0L;\n    try (\n      StreamWriter<ProjectDump.Analysis> output = dumpWriter.newStreamWriter(DumpElement.ANALYSES);\n      DbSession dbSession = dbClient.openSession(false);\n      PreparedStatement stmt = buildSelectStatement(dbSession);\n      ResultSet rs = stmt.executeQuery()) {\n\n      ProjectDump.Analysis.Builder builder = ProjectDump.Analysis.newBuilder();\n      while (rs.next()) {\n        // Results are ordered by ascending id so that any parent is located\n        // before its children.\n        ProjectDump.Analysis analysis = convertToAnalysis(rs, builder);\n        output.write(analysis);\n        count++;\n      }\n      LoggerFactory.getLogger(getClass()).debug(\"{} analyses exported\", count);\n\n    } catch (Exception e) {\n      throw new IllegalStateException(format(\"Analysis Export failed after processing %d analyses successfully\", count), e);\n    }\n  }\n\n  private PreparedStatement buildSelectStatement(DbSession dbSession) throws SQLException {\n    PreparedStatement stmt = dbClient.getMyBatis().newScrollingSelectStatement(dbSession, QUERY);\n    try {\n      stmt.setString(1, projectHolder.projectDto().getUuid());\n      stmt.setBoolean(2, true);\n      stmt.setString(3, STATUS_PROCESSED);\n      stmt.setBoolean(4, true);\n      return stmt;\n    } catch (Exception t) {\n      DatabaseUtils.closeQuietly(stmt);\n      throw t;\n    }\n  }\n\n  private ProjectDump.Analysis convertToAnalysis(ResultSet rs, ProjectDump.Analysis.Builder builder) throws SQLException {","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStep.java#L71-L107","documentation":"ExportAnalysesStep.execute() scrolls all ANALYSES rows for the project and writes them to the dump output. Any exception during the streaming (SQL error, protobuf serialization failure, IO error on the output) is wrapped in an IllegalStateException that reports how many analyses were exported successfully before the failure, to aid resume/debug of the CE export task.","triggerScenarios":"SQLException while scrolling the analyses select; ProjectDump.Analysis protobuf write fails; DB connection dropped mid-scroll; corrupt analysis data that fails conversion.","commonSituations":"Database connectivity issues during long CE project export; schema drift after SonarQube upgrade (missing columns expected by the QUERY); broken dump output stream (disk full, connection to destination closed).","solutions":["Inspect the cause (getCause()) for the real failure — usually a SQLException — and fix the DB issue (connectivity, locks, missing column).","Verify the sonarqube DB schema matches the running SonarQube version; run the upgrade/migration step if not.","Check disk space and network to the dump destination; retry the CE task after fixing.","Identify the problematic analysis row via the logged count and repair or remove the corrupt row."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"int analyses = dbClient.getPlatformDbClient().countAnalyses(projectUuid); // pre-check data access before export","typeGuard":null,"tryCatchPattern":"try {\n  exportAnalysesStep.execute(context);\n} catch (IllegalStateException e) {\n  logger.error(\"Analysis export failed after {}; cause: {}\", parseCount(e.getMessage()), e.getCause(), e);\n  throw new JobFailure(e.getCause());\n}","preventionTips":["Keep DB schema in sync with the SonarQube version (run upgrades fully)","Monitor DB connectivity/timeouts for long CE tasks","Ensure sufficient disk space for dump output","Log the wrapped cause, not just the wrapper message"],"tags":["export","database","streaming","sonarqube"],"backgroundTag":"database-query-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"}