# Errors

Predefined error strings Error names in Amazon States Language - https://states-language.net/spec.html#appendix-a Error handling in Step Functions - https://docs.aws.amazon.com/step-functions/latest/dg/concepts-error-handling.html.

- Source: [`aws-stepfunctions/lib/types.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-stepfunctions/lib/types.ts#L57)

## Example

```ts
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';

// create a table
const table = new dynamodb.Table(this, 'montable', {
  partitionKey: {
    name: 'id',
    type: dynamodb.AttributeType.STRING,
  },
});

const finalStatus = new sfn.Pass(this, 'final step');

// States language JSON to put an item into DynamoDB
// snippet generated from https://docs.aws.amazon.com/step-functions/latest/dg/tutorial-code-snippet.html#tutorial-code-snippet-1
const stateJson = {
  Type: 'Task',
  Resource: 'arn:aws:states:::dynamodb:putItem',
  Parameters: {
    TableName: table.tableName,
    Item: {
      id: {
        S: 'MyEntry',
      },
    },
  },
  ResultPath: null,
};

// custom state which represents a task to insert data into DynamoDB
const custom = new sfn.CustomState(this, 'my custom task', {
  stateJson,
});

// catch errors with addCatch
const errorHandler = new sfn.Pass(this, 'handle failure');
custom.addCatch(errorHandler);

// retry the task if something goes wrong
custom.addRetry({
  errors: [sfn.Errors.ALL],
  interval: Duration.seconds(10),
  maxAttempts: 5,
});

const chain = sfn.Chain.start(custom)
  .next(finalStatus);

const sm = new sfn.StateMachine(this, 'StateMachine', {
  definitionBody: sfn.DefinitionBody.fromChainable(chain),
  timeout: Duration.seconds(30),
  comment: 'a super cool state machine',
});

// don't forget permissions. You need to assign them
table.grantWriteData(sm);
```

## Initializer

```ts
new Errors()
```

## Properties

- `ALL`: string (static) — Matches any Error.

- `BRANCH_FAILED`: string (static) — A branch of a Parallel state failed.

- `HEARTBEAT_TIMEOUT`: string (static) — A Task State failed to heartbeat for a time longer than the “HeartbeatSeconds” value.

- `NO_CHOICE_MATCHED`: string (static) — A Choice state failed to find a match for the condition field extracted from its input.

- `PARAMETER_PATH_FAILURE`: string (static) — Within a state’s “Parameters” field, the attempt to replace a field whose name ends in “.$” using a Path failed.

- `PERMISSIONS`: string (static) — A Task State failed because it had insufficient privileges to execute the specified code.

- `RESULT_PATH_MATCH_FAILURE`: string (static) — A Task State’s “ResultPath” field cannot be applied to the input the state received.

- `TASKS_FAILED`: string (static) — A Task State failed during the execution.

- `TIMEOUT`: string (static) — A Task State either ran longer than the “TimeoutSeconds” value, or failed to heartbeat for a time longer than the “HeartbeatSeconds” value.
