# Exit codes

> The exit codes every geni command uses, so a script can branch on what went wrong.

Source: https://docs.generalinput.com/cli/exit-codes



Commands share one set of exit codes. A few commands add a meaning of their own on top, noted on their page.

| Code  | Name                       | Meaning                                                                                                               |
| ----- | -------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| `0`   | Success                    | The command did what it was asked.                                                                                    |
| `1`   | Generic error              | Something went wrong that has no more specific code.                                                                  |
| `2`   | Invalid arguments          | A flag or argument was missing, malformed, or not one of the allowed values.                                          |
| `4`   | Not found                  | The id or slug does not exist in the active workspace, or you cannot see it.                                          |
| `5`   | Forbidden                  | You can see the resource but may not do this with it. Also a declined login.                                          |
| `9`   | Validation failed          | [`validate`](/cli/resource/validate) or [`publish`](/cli/resource/publish) rejected the files. Nothing was published. |
| `77`  | Credential resolve failed  | The server refused to resolve a credential for [`exec bash`](/cli/exec/bash). Do not retry.                           |
| `78`  | Session missing or expired | No local session, or the server rejected it. Run [`geni login`](/cli/auth/login).                                     |
| `79`  | Upgrade required           | This `geni` is below the server's minimum version. Run [`geni upgrade`](/cli/upgrade).                                |
| `124` | Timeout                    | The command gave up waiting.                                                                                          |
| `125` | Internal error             | An unexpected failure, or the server returned a 5xx. Retry once before reporting.                                     |

## How an API failure maps [#how-an-api-failure-maps]

When a command's request fails, the HTTP status decides the code:

| HTTP  | Exit  |
| ----- | ----- |
| `401` | `78`  |
| `403` | `5`   |
| `404` | `4`   |
| `426` | `79`  |
| `5xx` | `125` |
| other | `125` |

## The exception: `geni exec bash` [#the-exception-geni-exec-bash]

[`geni exec bash`](/cli/exec/bash) forwards the subprocess's own exit code, so `0` through `125` mean whatever your command meant by them. Only `77`, `78`, and `125` are `geni`'s own, and they are only reached when the call never got as far as running your command.

## In a script [#in-a-script]

```sh
if ! geni resource validate --json > result.json; then
  case $? in
    9)  echo "validation failed"; jq -r '.errors[].message' result.json ;;
    78) echo "session expired"; geni login ;;
    79) geni upgrade && geni skills install ;;
    *)  echo "unexpected failure" ;;
  esac
fi
```
