# Errore

Canonical URL: https://developers.iagenify.com/pt/sdk/agent/events/error/
Language: pt

`{ type: "error", message, code }`

La run va fail. E' emanata poco prima di run() rejet — quindi è un notizion, non un stato recuperabile.

Status: the run then rejects · rare · tool failures are not this

## Campos {#fields}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `message` | string |  | Messaggio del erro. |
| `code` | string |  | Su cod, quando ha un — `context_too_large`, `turn_failed`, `unauthorized`. |

## Que non è un evento di erro {#not-this}

| Situazione | Anunciat |
| --- | --- |
| Un utensilio gettato | `tool_end` con `ok: false` — il loop continua |
| Un utensilio fu resistit | `tool_end` con `refused: true` |
| Un virat failed e sta sendo rejuziat | `retry` |
| Un modele ha ceduto e il proximo è usa | `fallback` |
| Un soffit era alzat | `done` con `stopReason` |

> **Quasi tutto ciò che va mal è manegnat dentro del loop**
>
> Un evento di errore significa che il loop non può continuare — il virare a fault su ogni model dopo ogni tentazione, il contesto non vat, la sessione non è autorizzata. Ciascuna di esse è una condizione a cui il code has de reagire, non una che l'agente puè lavorare.

## Manejar-lo {#handling}

```javascript
import { IaGenifyError, NotEnoughCredits } from "iagenify";

try {
  await agent.run({ inputs, onEvent });
} catch (err) {
  if (err instanceof NotEnoughCredits) {
    // Never retried, on any model. Top up.
  } else if (err instanceof IaGenifyError && err.code === "context_too_large") {
    await agent.compact();
  } else {
    throw err;
  }
}
```

L'evento e il rejet portano la medesima cosa — l'evento existe per una interface puèt mostrarlo senza attendere la promessa di stereo.

## A subagent that fails does not fail the run {#task}

Il suo fallimento è emanat come un `error` che porta `parentId`, e il `task` termina l'appello con `ok: false`. Il padre prosegue con il risultato del outil — un delegat che non puèt fare il suo lavoro è informazion, non un crash.

- [Alternativas e novas tentativas](/pt/sdk/agent/fallback-and-retry): Cenès estentat prima di questo.
- [Erros](/pt/sdk/concepts/errors): Le classie di erro.

```python
from iagenify import IaGenifyError, NotEnoughCredits

try:
    agent.run(inputs=inputs, on_event=on_event)
except NotEnoughCredits:
    pass  # Never retried, on any model. Top up.
except IaGenifyError as error:
    if error.code != "context_too_large":
        raise
    agent.compact()
```
