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
- 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
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
- 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
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
- Measure Export failed after processing %d measures successfu
- New Code Periods Export failed after processing %d new code
- Settings Export failed after processing %d settings successf
- Analysis report %s part %s is missing in database
- Analysis Export failed after processing %d analyses successf
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/5c7145947da285f2.
Report an issue: GitHub.