task.run throws RunError without the ECS failure reason
When RunTask fails, task.run in sst/aws/task throws RunError("Failed to run task") with the raw fetch Response attached as .response. We see this happen in rare cases, but not rare enough to let it slip.
There are two problems:
The Response serializes to {}. Logging the error (for example console.error(err) or through a structured logger) gives {"response":{}}, with no status code and no body.
When ECS returns HTTP 200 with no tasks, the reason is lost for good. The body has already been read by res.json(), so the caller can't get at failures[]. That array is where ECS reports placement errors such as Capacity is unavailable at this time or RESOURCE:ENI.
if (!res.ok) throw new RunError(res);
const data = await res.json();
if (!data.tasks?.length) throw new RunError(res); // body already consumedThis makes intermittent Fargate capacity failures impossible to diagnose from application logs.
Expected
RunError should expose the parsed information, for example:
class RunError extends Error {
status: number;
errorType?: string; // e.g. "ThrottlingException" (from __type)
failures?: { arn?: string; reason?: string; detail?: string }[];
body?: unknown; // parsed JSON response
}Ideally the message would include the reason too, for example Failed to run task: Capacity is unavailable at this time.
task.stop and task.describe follow the same pattern and would benefit from the same fix.
Tested on: [email protected]
Source: anomalyco/sst