{"record":{"id":"5c7145947da285f2","repo":"SonarSource/sonarqube","slug":"metric-export-failed-after-processing-d-metrics-s","errorCode":null,"errorMessage":"Metric Export failed after processing %d metrics successfully","messagePattern":"Metric Export failed after processing (.+?) metrics successfully","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportMetricsStep.java","lineNumber":67,"sourceCode":"    try (\n      StreamWriter<ProjectDump.Metric> output = dumpWriter.newStreamWriter(DumpElement.METRICS);\n      DbSession dbSession = dbClient.openSession(false)) {\n\n      ProjectDump.Metric.Builder builder = ProjectDump.Metric.newBuilder();\n      Map<String, Integer> refByUuid = metricsHolder.getRefByUuid();\n      List<MetricDto> dtos = dbClient.metricDao().selectByUuids(dbSession, refByUuid.keySet());\n      for (MetricDto dto : dtos) {\n        builder\n          .clear()\n          .setRef(refByUuid.get(dto.getUuid()))\n          .setKey(dto.getKey())\n          .setName(defaultString(dto.getShortName()));\n        output.write(builder.build());\n        count++;\n      }\n      LoggerFactory.getLogger(getClass()).debug(\"{} metrics exported\", count);\n    } catch (Exception e) {\n      throw new IllegalStateException(format(\"Metric Export failed after processing %d metrics successfully\", count), e);\n    }\n  }\n\n  @Override\n  public String getDescription() {\n    return \"Export metrics\";\n  }\n}\n","sourceCodeStart":49,"sourceCodeEnd":76,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportMetricsStep.java#L49-L76","documentation":"ExportMetricsStep.execute() iterates metric DTOs and writes protobuf Metric messages to the export output, counting successes. Any exception during iteration or writing is wrapped in an IllegalStateException stating how many metrics were exported before failing. SonarQube throws this because a compute-engine export task must abort rather than produce a partial dump silently.","triggerScenarios":"Exception while iterating metrics from the database or while calling output.write(builder.build()) inside execute() — e.g. DB read failure, null/unexpected DTO field breaking defaultString handling, or serialization/I/O error on the dump stream.","commonSituations":"DB connectivity loss during export; a custom or deprecated metric row with unexpected data; disk write error on the CE worker while producing the dump file.","solutions":["Check the wrapped cause for the real failure and address it (DB error, bad row, I/O error)","Verify database health and rerun the CE task after transient DB issues clear","Check disk space and write permissions on the CE worker's dump directory","If a specific metric row is corrupt, fix or remove that row in the METRICS table"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// verify DB reachable and metrics table readable before export\nif (!dbClient.getDatabase().isOnline()) {\n  throw new IllegalStateException(\"Database not available for metric export\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  step.execute(context);\n} catch (IllegalStateException e) {\n  LOGGER.error(\"Metric export aborted; root cause: {}\", e.getCause(), e);\n}","preventionTips":["Keep the database healthy; watch for connection pool exhaustion during CE activity","Audit custom/deprecated metric rows for null or malformed fields","Ensure adequate disk space on CE workers"],"tags":["database","export","compute-engine","metrics"],"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"}