# fail

Learn how to terminate execution with an error.

This action terminates template execution with an error message.

It works well as an early guard to abort when a required condition is not met. For example, you can stop execution with a clear message and helpful links when no supported framework is detected in the current directory.

## Example

The following template checks for a Next.js project and fails with a helpful message if none is found:

**template.json5**

```json5
{
  "$schema": "https://schema.croct.com/json/v1/template.json",
  "title": "Next.js check",
  "description": "Fails if no Next.js project is detected.",
  "actions": [
    {
      "name": "test",
      "condition": "${project.platform === 'unknown'}",
      "then": [
        {
          "name": "fail",
          "title": "Project not found",
          "message": "This template requires a Next.js project.",
          "details": [
            "No supported framework detected in the current directory."
          ],
          "suggestions": [
            "Navigate to your project directory and try again."
          ],
          "links": [
            {
              "label": "Getting started",
              "url": "https://croct.com/docs/getting-started"
            }
          ]
        }
      ]
    }
  ]
}
```

To apply this template, run:

```sh
croct use template.json5
```

## Properties

These are the supported properties:

- `name`: `string`

  The action identifier. Always `fail` for this action.

- `message`: `string`

  The error message to display.

- `title`: `string` (optional)

  A short title for the error.

- `details`: `Array<string>` (optional)

  A list of details providing additional context about the error.

- `suggestions`: `Array<string>` (optional)

  A list of suggestions to help the user resolve the issue.

- `links`: `Array<object>` (optional)

  A list of links with additional information.

  - `label`: `string`

    The display text for the link.

  - `url`: `string`

    The URL to link to.

## Explore

- [Test](/reference/cli/templates/actions/test): Learn how to branch based on conditions.
- [Try](/reference/cli/templates/actions/try): Learn how to catch errors instead of aborting.
- [Check dependency](/reference/cli/templates/actions/check-dependency): Learn how to check a prerequisite before failing.
- [Print](/reference/cli/templates/actions/print): Learn how to print a message before failing.
