{"record":{"id":"8d0b6520c2406eac","repo":"Cysharp/UniTask","slug":"the-tasks-argument-contains-no-tasks","errorCode":null,"errorMessage":"The tasks argument contains no tasks.","messagePattern":"The tasks argument contains no tasks\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAny.cs","lineNumber":186,"sourceCode":"            }\n\n            void IUniTaskSource.GetResult(short token)\n            {\n                GetResult(token);\n            }\n        }\n\n\n        sealed class WhenAnyPromise<T> : IUniTaskSource<(int, T)>\n        {\n            int completedCount;\n            UniTaskCompletionSourceCore<(int, T)> core;\n\n            public WhenAnyPromise(UniTask<T>[] tasks, int tasksLength)\n            {\n                if (tasksLength == 0)\n                {\n                    throw new ArgumentException(\"The tasks argument contains no tasks.\");\n                }\n\n                TaskTracker.TrackActiveTask(this, 3);\n\n                for (int i = 0; i < tasksLength; i++)\n                {\n                    UniTask<T>.Awaiter awaiter;\n                    try\n                    {\n                        awaiter = tasks[i].GetAwaiter();\n                    }\n                    catch (Exception ex)\n                    {\n                        core.TrySetException(ex);\n                        continue; // consume others.\n                    }\n\n                    if (awaiter.IsCompleted)","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/Cysharp/UniTask/blob/ceac8d6946b1125fe782cd171fbcb245b567dbf9/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenAny.cs#L168-L204","documentation":"Thrown by WhenAnyPromise<T> constructor (the generic WhenAny for UniTask<T>) when tasksLength is zero. WhenAny semantically requires at least one task to race; with zero tasks there is nothing to await and the result is undefined. UniTask rejects this at construction rather than hanging forever.","triggerScenarios":"Calling UniTask.WhenAny(emptyArray) or WhenAny(list.ToArray()) on an empty collection. Passing a tasks array whose effective length (tasksLength) is zero.","commonSituations":"Dynamically building a task list that ends up empty due to filtering or all items being skipped. A race between populating a list and calling WhenAny. Editor or test scenarios with no registered tasks.","solutions":["Check that the task collection is non-empty before calling WhenAny","Fall back to a default task or UniTask.Never when the list is empty","Guard with: if (tasks.Count == 0) return; before WhenAny"],"exampleFix":"// before\nvar (winIndex, _) = await UniTask.WhenAny(tasks.ToArray());\n\n// after\nif (tasks.Count == 0) return;\nvar (winIndex, _) = await UniTask.WhenAny(tasks.ToArray());","handlingStrategy":"validation","validationCode":"if (tasks == null || tasks.Length == 0)\n{\n    // handle empty case: return default, await Never, or skip\n    return default;\n}\nvar (winIndex, result) = await UniTask.WhenAny(tasks);","typeGuard":"static bool HasAnyTasks<T>(UniTask<T>[] tasks) => tasks != null && tasks.Length > 0;","tryCatchPattern":null,"preventionTips":["Check task array length before calling WhenAny","Fall back to UniTask.Never or a default value when the collection is empty","Log when task collections are unexpectedly empty during development"],"tags":["unitask","whenany","argument-validation","unity","csharp"],"backgroundTag":null,"analyzedSha":"ceac8d6946b1125fe782cd171fbcb245b567dbf9","analyzedAt":"2026-08-13T19:16:39.025Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}