Repository: getmoto/moto

Issue:
Certain StepFunctions exceptions uncatchable
I am having an issue catching certain exceptions that are being thrown by only some of the StepFunction related methods.  I have managed to break it down to this simple example to illustrate my problem:

```
import pytest
import moto
from moto import mock_stepfunctions
import boto3

from botocore.exceptions import ClientError

def test_sfn_describe_state_machine():
    with mock_stepfunctions():
        with pytest.raises(ClientError):
            client = boto3.client("stepfunctions", region_name="ap-southeast-2")
            client.describe_state_machine(stateMachineArn="asd")

def test_sfn_start_execution():
    with mock_stepfunctions():
        with pytest.raises(ClientError):
            client = boto3.client("stepfunctions", region_name="ap-southeast-2")
            client.start_execution(stateMachineArn="asd")

```

Running this with pytest (or anything, that part isn't relevant) will result in the first test passing, with the `ClientError` successfully being caught.  The second test will fail.  From what I can see, the two methods are raising two different exceptions:

1st) `botocore.errorfactory.InvalidArn: An error occurred (InvalidArn) when calling the DescribeStateMachine operation: Invalid State Machine Arn: 'asd'`
2nd) `moto.stepfunctions.exceptions.InvalidArn: Invalid State Machine Arn: 'asd'`

From what I can see, they're both calling the same code path to validate the ARN, but only one is raising exception namespace to `moto`.  I've also had a look at the tests in the `moto` repository itself and added one that follows the pattern of my failing test, and it fails there too - so I don't think this is an environment issue.

I'm sure it's something obvious, but it's got my stumped at the moment.


Discussion:
Hi @aidan-, our `describe_state_machine`-function catches errors properly, and returns the error details in the correct format:
https://github.com/spulec/moto/blob/master/moto/stepfunctions/responses.py#L81

The `start_execution`-function doesn't catch anything, and simply throws the Exception as is:
https://github.com/spulec/moto/blob/master/moto/stepfunctions/responses.py#L95

Thanks for raising it - marking it as a bug.

Resolving patch:
diff --git a/moto/stepfunctions/responses.py b/moto/stepfunctions/responses.py
--- a/moto/stepfunctions/responses.py
+++ b/moto/stepfunctions/responses.py
@@ -95,7 +95,10 @@ def list_tags_for_resource(self):
     def start_execution(self):
         arn = self._get_param("stateMachineArn")
         name = self._get_param("name")
-        execution = self.stepfunction_backend.start_execution(arn, name)
+        try:
+            execution = self.stepfunction_backend.start_execution(arn, name)
+        except AWSError as err:
+            return err.response()
         response = {
             "executionArn": execution.execution_arn,
             "startDate": execution.start_date,


Test patch:
diff --git a/tests/test_stepfunctions/test_stepfunctions.py b/tests/test_stepfunctions/test_stepfunctions.py
--- a/tests/test_stepfunctions/test_stepfunctions.py
+++ b/tests/test_stepfunctions/test_stepfunctions.py
@@ -253,6 +253,15 @@ def test_state_machine_throws_error_when_describing_unknown_machine():
         client.describe_state_machine(stateMachineArn=unknown_state_machine)
 
 
+@mock_stepfunctions
+@mock_sts
+def test_state_machine_throws_error_when_describing_bad_arn():
+    client = boto3.client("stepfunctions", region_name=region)
+    #
+    with assert_raises(ClientError) as exc:
+        client.describe_state_machine(stateMachineArn="bad")
+
+
 @mock_stepfunctions
 @mock_sts
 def test_state_machine_throws_error_when_describing_machine_in_different_account():
@@ -362,6 +371,15 @@ def test_state_machine_start_execution():
     execution["startDate"].should.be.a(datetime)
 
 
+@mock_stepfunctions
+@mock_sts
+def test_state_machine_start_execution_bad_arn_raises_exception():
+    client = boto3.client("stepfunctions", region_name=region)
+    #
+    with assert_raises(ClientError) as exc:
+        client.start_execution(stateMachineArn="bad")
+
+
 @mock_stepfunctions
 @mock_sts
 def test_state_machine_start_execution_with_custom_name():
@@ -446,7 +464,7 @@ def test_state_machine_describe_execution():
 
 @mock_stepfunctions
 @mock_sts
-def test_state_machine_throws_error_when_describing_unknown_machine():
+def test_execution_throws_error_when_describing_unknown_execution():
     client = boto3.client("stepfunctions", region_name=region)
     #
     with assert_raises(ClientError) as exc: