title: State machine ignores step function errors
body: <p>I have a problem with my aws step functions workflow. I have defined multiple states and I wanted to add error handling to them. The problem is, that for any error from function (raised exception, unhandled promise rejection or code errors) state machine always gets LambdaFunctionSucceeded and continues execution until last state finishes.</p>
  
  <p>Here is example of state machine definition, I do not provide my own definition, because it is overcomplicated for this example</p>
  
  <pre><code>{
      "Comment": "Example state machine",
      "StartAt": "State1",
      "States": {
          "State1": {
              "Type": "Task",
              "Resource": "arn:aws:lambda:eu-west-2:123456789012:function:State1Function",
              "Next": "Finish",
              "ResultPath": "$.State1Result",
              "Catch": [
                  {
                      "ErrorEquals": [
                          "States.TaskFailed"
                      ],
                      "Next": "Failure"
                  }
              ]
          },
          "Failure": {
              "Type": "Fail",
              "Error": "$"
          },
          "Finish": {
              "Type": "Task",
              "Resource": "arn:aws:lambda:eu-west-2:123456789012:function:FinishFunction",
              "End": true,
              "Catch": [
                  {
                      "ErrorEquals": [
                          "States.TaskFailed"
                      ],
                      "Next": "Failure"
                  }
              ]
          }
      }
  }
  </code></pre>
  
  <p>State1Function example:</p>
  
  <pre class="lang-js prettyprint-override"><code>module.exports = async event =&gt; {
      not().defined; // but execution does not fail
      // do stuff
  };
  </code></pre>
  
  <p>I test it in local environment using <code>sam local start-lambda</code> and <code>amazon/aws-stepfunctions-local</code> docker image. Output of <code>sam</code> for State1Function execution:</p>
  
  <blockquote>
    <p>2019-11-19T08:37:40.910Z        b2421c61-d31c-1482-6a65-f6cbd42328a7    ERROR   Invoke Error    {"errorType":"ReferenceError","errorMessage":"not is not defined","stack":["ReferenceError: not is not defined","    at Runtime.module.exports [as handler] (/var/task/path/to/state1function.js:7:5)","    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"]}</p>
  </blockquote>
  
  <p>Output from <code>amazon/aws-stepfunctions-local</code> container (which handles state machine execution):</p>
  
  <blockquote>
    <p>2019-11-19 08:37:41.348: arn:aws:states:eu-west-2:123456789012:execution:test:test4 : {"Type":"LambdaFunctionSucceeded","PreviousEventId":4,"LambdaFunctionSucceededEventDetails":{"Output":"{\"errorType\":\"ReferenceError\",\"errorMessage\":\"not is not defined\"}"}}</p>
  </blockquote>
  
  <p>The execution continued.</p>
  
  <p>When I stopped <code>sam local start-lambda</code> and state machine was unable to call one of step functions, the output was:</p>
  
  <blockquote>
    <p>2019-11-19 08:37:53.406: arn:aws:states:eu-west-2:123456789012:execution:test:test4 : {"Type":"LambdaFunctionFailed","PreviousEventId":23,"LambdaFunctionFailedEventDetails":{"Error":"Lambda.SdkClientException","Cause":"Unable to execute HTTP request: The target server failed to respond"}}</p>
  </blockquote>
  
  <p>Execution failed then. I would expect similar behaviour on step function errors.</p>
  
  <p>What is the proper way to handle step function failures? </p>