gradle/gradle · error · WorkerExecutionException
There was a failure while executing work items
Error message
There was a failure while executing work items
What it means
When a task that used the Worker API finishes, DefaultWorkerExecutor.await() waits for outstanding work items. If exactly one item failed, its failure surfaces as a single-cause WorkerExecutionException('There was a failure while executing work items'). The real error is in the causes list, not this wrapper message.
Source
Thrown at platforms/core-execution/workers/src/main/java/org/gradle/workers/internal/DefaultWorkerExecutor.java:209
try {
asyncWorkTracker.waitForCompletion(currentOperation, RETAIN_PROJECT_LOCKS);
} catch (DefaultMultiCauseException e) {
throw workerExecutionException(e.getCauses());
}
}
private void await(List<AsyncWorkCompletion> workItems) throws WorkExecutionException {
BuildOperationRef currentOperation = buildOperationRunner.getCurrentOperation();
try {
asyncWorkTracker.waitForCompletion(currentOperation, workItems, RETAIN_PROJECT_LOCKS);
} catch (DefaultMultiCauseException e) {
throw workerExecutionException(e.getCauses());
}
}
private WorkerExecutionException workerExecutionException(List<? extends Throwable> failures) {
if (failures.size() == 1) {
throw new WorkerExecutionException("There was a failure while executing work items", failures);
} else {
throw new WorkerExecutionException("There were multiple failures while executing work items", failures);
}
}
WorkerRequirement getWorkerRequirement(Class<?> executionClass, WorkerSpec configuration, WorkParameters parameters) {
if (configuration instanceof ProcessWorkerSpec) {
DaemonForkOptionsBuilder builder = new DaemonForkOptionsBuilder(forkOptionsFactory)
.keepAliveMode(KeepAliveMode.SESSION);
ProcessWorkerSpec processConfiguration = (ProcessWorkerSpec) configuration;
JavaForkOptions forkOptions = forkOptionsFactory.newJavaForkOptions();
processConfiguration.getForkOptions().copyTo(forkOptions);
forkOptions.setWorkingDir(workerDirectoryProvider.getWorkingDirectory());
ClassPath isolatedFromChanges = classpathTransformer.copyingTransform(DefaultClassPath.of(processConfiguration.getClasspath()));
builder.javaForkOptions(forkOptions)
.withClassLoaderStructure(classLoaderStructureProvider.getWorkerProcessClassLoaderStructure(isolatedFromChanges.getAsFiles(), getParamClasses(executionClass, parameters)));
View on GitHub (pinned to 534f27719b)
Solutions
- Read WorkerExecutionException.getCauses() - the first cause is the actual failure from the WorkAction
- Fix the underlying cause in the work action implementation
- Rerun with --stacktrace to see the full cause chain if the console truncated it
Defensive patterns
Strategy: try-catch
Try / catch
try {
workQueue.await();
} catch (WorkerExecutionException e) {
Throwable real = e.getCauses().get(0); // single failure: this is the WorkAction's error
// report/handle 'real', not the wrapper
} Prevention
- Wrap WorkAction bodies with contextual information before throwing so causes are self-explanatory
- Catch WorkerExecutionException at task boundaries and log all causes
- Validate work inputs inside the action and fail with precise messages
When it happens
Trigger: One WorkAction threw during execution; asyncWorkTracker.waitForCompletion raises DefaultMultiCauseException with a single cause, which workerExecutionException converts to this one-cause WorkerExecutionException (size == 1 branch).
Common situations: Any exception inside a WorkAction execute() - forked compiler failure, NPE in a transformation, missing input file - surfacing at await() time, often with a stack trace pointing only at the await site.
Related errors
- There were multiple failures while executing work items
- Setting the working directory of a worker is not supported.
- An attempt was made to submit work from a thread not managed
- Cannot call %s on %s as changes to this collection are disal
- Cannot add a %s with name '%s' as a %s with that name alread
AI-assisted analysis of gradle/gradle@534f27719b (2026-08-22).
Data as JSON: /api/errors/841552b9357737f0.
Report an issue: GitHub.