# Errors

> Handle failed turns, command executions, MCP calls, and process errors safely.

The SDK reports structured error items in a turn's `items` collection and rejects failures that prevent a turn from completing. MCP tool calls expose a failed status and an error message.

```ts
try {
  const turn = await thread.run("Run the tests");
  const errors = turn.items.filter((item) => item.type === "error");
  console.log(errors);
} catch (error) {
  console.error("Codex process failed", error);
}
```

Do not treat a command or MCP tool call's non-success status as a successful turn. Preserve the structured item for diagnostics and show the user enough context to decide whether to retry.
