# Find a run that failed

Filter a project's [runs](/docs/concepts/runs.md) by status to find the failed ones, then open one to read its error.

## Before you start

You need a run that failed. Follow [Write a task](/docs/orchestration/tasks.md) with this task instead, then run it once with `{}` as its payload:

```ts title="tasks/check-stock.ts"
export default {
  name: "check-stock",
  description: "Check a product's stock.",
  schedulable: true,
  async run() {
    throw new Error("The stock service did not answer.");
  },
};
```

## Find the run that failed

**Studio**

1. In your project, open **Orchestration** > **Runs**.
2. Click **Status**.
3. Tick **Failed**. Studio lists only the runs that failed.
4. Click **Open** on the `check-stock` run. You should now see its **Error**: the message `The stock service did not answer.` and the `code` `TASK_EXECUTION_FAILED`.

**Code**

1. [Sign in](/docs/start/authentication.md) to the CLI.
2. Set `PROJECT` to your project's ID ([Find your IDs](/docs/authentication/api-keys.md#find-your-ids)): `export PROJECT=<id>`.
3. List the runs that failed. You should now see only runs with `"status": "failed"`, each with its `error`:

```bash
npx veryfront project runs project-list --project-reference $PROJECT --query '{"status":["failed"]}'
```

### Try it in a sandbox

```playground
step: Add a task that fails | curl -fsS -X PUT https://api.veryfront.com/projects/$VERYFRONT_PROJECT_REFERENCE/files/tasks%2Fcheck-stock.ts -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{"content":"export default { name: \"check-stock\", async run() { throw new Error(\"The stock service did not answer.\"); } };"}'
step: Run it | curl -fsS -X POST https://api.veryfront.com/runs -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{"project_id":"'$VERYFRONT_PROJECT_ID'","target":{"type":"task","id":"check-stock"},"input":{}}'
step: Set PROJECT | export PROJECT=$VERYFRONT_PROJECT_ID
check: npx veryfront project runs project-list --project-reference $PROJECT --query '{"status":["failed"]}'
expect: The stock service did not answer.
```

**API**

1. Set `PROJECT` to your project's ID ([Find your IDs](/docs/authentication/api-keys.md#find-your-ids)): `export PROJECT=<id>`.
2. List the runs that failed, with your [API key](/docs/authentication/api-keys.md). You should now see only runs with `"status": "failed"`, each with its `error`:

```bash
curl "https://api.veryfront.com/projects/$PROJECT/runs?status=failed" \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

Repeat `status` to match several, and add `target_type` (`agent`, `task` or `workflow`) to narrow the list.

## With MCP

1. Call `veryfront__list_project_runs` with `{ "project_reference": "my-project", "status": ["failed"] }`. The project reference is its slug or its ID.
2. It worked when every run in the answer has `"status": "failed"` and an `error` with its `message`.

## Next steps

* [Debug a run](/docs/observability/debug.md)
* [Search logs](/docs/observability/logs.md)
