SonarSource/sonarqube · error · IllegalStateException

Metric Export failed after processing %d metrics successfull

Error message

Metric Export failed after processing %d metrics successfully

What it means

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.

Source

Thrown at server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportMetricsStep.java:67

    try (
      StreamWriter<ProjectDump.Metric> output = dumpWriter.newStreamWriter(DumpElement.METRICS);
      DbSession dbSession = dbClient.openSession(false)) {

      ProjectDump.Metric.Builder builder = ProjectDump.Metric.newBuilder();
      Map<String, Integer> refByUuid = metricsHolder.getRefByUuid();
      List<MetricDto> dtos = dbClient.metricDao().selectByUuids(dbSession, refByUuid.keySet());
      for (MetricDto dto : dtos) {
        builder
          .clear()
          .setRef(refByUuid.get(dto.getUuid()))
          .setKey(dto.getKey())
          .setName(defaultString(dto.getShortName()));
        output.write(builder.build());
        count++;
      }
      LoggerFactory.getLogger(getClass()).debug("{} metrics exported", count);
    } catch (Exception e) {
      throw new IllegalStateException(format("Metric Export failed after processing %d metrics successfully", count), e);
    }
  }

  @Override
  public String getDescription() {
    return "Export metrics";
  }
}

View on GitHub (pinned to 184c821202)

Solutions

  1. Check the wrapped cause for the real failure and address it (DB error, bad row, I/O error)
  2. Verify database health and rerun the CE task after transient DB issues clear
  3. Check disk space and write permissions on the CE worker's dump directory
  4. If a specific metric row is corrupt, fix or remove that row in the METRICS table
Defensive patterns

Strategy: try-catch

Validate before calling

// verify DB reachable and metrics table readable before export
if (!dbClient.getDatabase().isOnline()) {
  throw new IllegalStateException("Database not available for metric export");
}

Try / catch

try {
  step.execute(context);
} catch (IllegalStateException e) {
  LOGGER.error("Metric export aborted; root cause: {}", e.getCause(), e);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/5c7145947da285f2. Report an issue: GitHub.