{"record":{"id":"841552b9357737f0","repo":"gradle/gradle","slug":"there-was-a-failure-while-executing-work-items","errorCode":null,"errorMessage":"There was a failure while executing work items","messagePattern":"There was a failure while executing work items","errorType":"exception","errorClass":"WorkerExecutionException","httpStatus":null,"severity":"error","filePath":"platforms/core-execution/workers/src/main/java/org/gradle/workers/internal/DefaultWorkerExecutor.java","lineNumber":209,"sourceCode":"        try {\n            asyncWorkTracker.waitForCompletion(currentOperation, RETAIN_PROJECT_LOCKS);\n        } catch (DefaultMultiCauseException e) {\n            throw workerExecutionException(e.getCauses());\n        }\n    }\n\n    private void await(List<AsyncWorkCompletion> workItems) throws WorkExecutionException {\n        BuildOperationRef currentOperation = buildOperationRunner.getCurrentOperation();\n        try {\n            asyncWorkTracker.waitForCompletion(currentOperation, workItems, RETAIN_PROJECT_LOCKS);\n        } catch (DefaultMultiCauseException e) {\n            throw workerExecutionException(e.getCauses());\n        }\n    }\n\n    private WorkerExecutionException workerExecutionException(List<? extends Throwable> failures) {\n        if (failures.size() == 1) {\n            throw new WorkerExecutionException(\"There was a failure while executing work items\", failures);\n        } else {\n            throw new WorkerExecutionException(\"There were multiple failures while executing work items\", failures);\n        }\n    }\n\n    WorkerRequirement getWorkerRequirement(Class<?> executionClass, WorkerSpec configuration, WorkParameters parameters) {\n        if (configuration instanceof ProcessWorkerSpec) {\n            DaemonForkOptionsBuilder builder = new DaemonForkOptionsBuilder(forkOptionsFactory)\n                .keepAliveMode(KeepAliveMode.SESSION);\n            ProcessWorkerSpec processConfiguration = (ProcessWorkerSpec) configuration;\n            JavaForkOptions forkOptions = forkOptionsFactory.newJavaForkOptions();\n            processConfiguration.getForkOptions().copyTo(forkOptions);\n            forkOptions.setWorkingDir(workerDirectoryProvider.getWorkingDirectory());\n\n            ClassPath isolatedFromChanges = classpathTransformer.copyingTransform(DefaultClassPath.of(processConfiguration.getClasspath()));\n            builder.javaForkOptions(forkOptions)\n                .withClassLoaderStructure(classLoaderStructureProvider.getWorkerProcessClassLoaderStructure(isolatedFromChanges.getAsFiles(), getParamClasses(executionClass, parameters)));\n","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/gradle/gradle/blob/534f27719b66953f95cc907aae7f2c1b12f5482d/platforms/core-execution/workers/src/main/java/org/gradle/workers/internal/DefaultWorkerExecutor.java#L191-L227","documentation":"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.","triggerScenarios":"One WorkAction threw during execution; asyncWorkTracker.waitForCompletion raises DefaultMultiCauseException with a single cause, which workerExecutionException converts to this one-cause WorkerExecutionException (size == 1 branch).","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    workQueue.await();\n} catch (WorkerExecutionException e) {\n    Throwable real = e.getCauses().get(0);  // single failure: this is the WorkAction's error\n    // report/handle 'real', not the wrapper\n}","preventionTips":["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"],"tags":["gradle","worker-api","execution","await"],"backgroundTag":"worker-action-failed","analyzedSha":"534f27719b66953f95cc907aae7f2c1b12f5482d","analyzedAt":"2026-08-22T08:09:12.375Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}