{"record":{"id":"db3cff8a3a983d8b","repo":"guzzle/promises","slug":"not-enough-promises-to-fulfill-count","errorCode":null,"errorMessage":"Not enough promises to fulfill count","messagePattern":"Not enough promises to fulfill count","errorType":"exception","errorClass":"AggregateException","httpStatus":null,"severity":"error","filePath":"src/Utils.php","lineNumber":277,"sourceCode":"\n        $promise = Each::of(\n            $promises,\n            function ($value, $idx, PromiseInterface $p) use (&$results, $count): void {\n                if (Is::settled($p)) {\n                    return;\n                }\n                $results[$idx] = $value;\n                if (count($results) >= $count) {\n                    $p->resolve(null);\n                }\n            },\n            function ($reason) use (&$rejections): void {\n                $rejections[] = $reason;\n            }\n        )->then(\n            function () use (&$results, &$rejections, $count) {\n                if (count($results) !== $count) {\n                    throw new AggregateException(\n                        'Not enough promises to fulfill count',\n                        $rejections\n                    );\n                }\n                ksort($results);\n\n                return array_values($results);\n            }\n        );\n\n        /** @var PromiseInterface<list<TValue>, \\Throwable> $promise */\n        return $promise;\n    }\n\n    /**\n     * Like some(), with 1 as count. However, if the promise fulfills, the\n     * fulfillment value is not an array of 1 but the value directly.\n     *","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/guzzle/promises/blob/42118e66a53c492effaf92bc357e931985d5c6f9/src/Utils.php#L259-L295","documentation":"Utils::some($count, $promises) resolves only when at least $count of the given promises fulfill; it tracks every rejection in parallel. When all input promises have settled and fewer than $count fulfilled, it throws this AggregateException carrying all the collected rejection reasons. The library throws it to signal that the caller asked for more successes than the input set could ever produce.","triggerScenarios":"Calling \\GuzzleHttp\\Promise\\Utils::some($n, $promises) where fewer than $n promises fulfill: too many input promises reject (or the array has fewer than $n entries), so the counting composite settles with count($results) !== $count.","commonSituations":"Racing N parallel HTTP requests and asking for more successes than actually arrive; a transient outage makes most requests fail; passing a $count larger than the array length; retry logic built on some() that does not tolerate partial failure.","solutions":["Lower the $count argument so it is <= the number of promises that can realistically fulfill.","Catch AggregateException and inspect getReason() to see why the inputs rejected, then retry the failed promises.","Verify the input array actually contains at least $count promises.","Replace some() with any() if only the first fulfillment matters, or use all()/settle() to observe every outcome."],"exampleFix":"// before\n$values = Utils::some(3, [$req1, $req2]); // only 2 promises: can never yield 3\n// after\ntry {\n    $values = Utils::some(2, [$req1, $req2, $req3]);\n} catch (AggregateException $e) {\n    foreach ($e->getReason() as $reason) { /* log/handle each rejection */ }\n}","handlingStrategy":"try-catch","validationCode":"if ($count < 1) { throw new \\InvalidArgumentException('$count must be >= 1'); }\nif (count($promises) < $count) { throw new \\LogicException('Fewer promises than requested count'); }","typeGuard":null,"tryCatchPattern":"try {\n    $values = \\GuzzleHttp\\Promise\\Utils::some($count, $promises);\n} catch (\\GuzzleHttp\\Promise\\AggregateException $e) {\n    // $e->getReason() is the array of rejection reasons\n    $values = []; // fallback\n}","preventionTips":["Always wrap some() calls in try-catch for AggregateException; partial failure is expected in racing patterns.","Ensure $count <= count($promises) before calling.","Prefer Utils::any() when only one success is needed.","Inspect getReason() to decide which promises to retry."],"tags":["promises","aggregate-exception","guzzle"],"backgroundTag":"value-out-of-range","analyzedSha":"42118e66a53c492effaf92bc357e931985d5c6f9","analyzedAt":"2026-09-14T00:10:14.865Z","contentChangedAt":"2026-09-14T00:10:14.865Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}