Repository: PrefectHQ/prefect

Issue:
Fargate agent kwarg literal parse can also raise SyntaxError
## Description
If a kwarg is passed to the Fargate agent such as `taskRoleArn='arn:aws:iam::543216789012:role/Dev'` the literal eval will raise a `SyntaxError` instead of the currently handled `ValueError`.



## Expected Behavior
I expect all kwargs to be properly parsed if they need to be, otherwise pass.






Discussion:

Resolving patch:
diff --git a/src/prefect/agent/fargate/agent.py b/src/prefect/agent/fargate/agent.py
--- a/src/prefect/agent/fargate/agent.py
+++ b/src/prefect/agent/fargate/agent.py
@@ -265,7 +265,7 @@ def _parse_kwargs(self, user_kwargs: dict, check_envars: bool = False) -> tuple:
                 try:
                     # Parse kwarg if needed
                     item = literal_eval(item)
-                except ValueError:
+                except (ValueError, SyntaxError):
                     pass
                 task_definition_kwargs.update({key: item})
                 self.logger.debug("{} = {}".format(key, item))
@@ -276,7 +276,7 @@ def _parse_kwargs(self, user_kwargs: dict, check_envars: bool = False) -> tuple:
                 try:
                     # Parse kwarg if needed
                     item = literal_eval(item)
-                except ValueError:
+                except (ValueError, SyntaxError):
                     pass
                 task_run_kwargs.update({key: item})
                 self.logger.debug("{} = {}".format(key, item))
@@ -290,7 +290,7 @@ def _parse_kwargs(self, user_kwargs: dict, check_envars: bool = False) -> tuple:
                     try:
                         # Parse env var if needed
                         def_env_value = literal_eval(def_env_value)  # type: ignore
-                    except ValueError:
+                    except (ValueError, SyntaxError):
                         pass
                     task_definition_kwargs.update({key: def_env_value})
 
@@ -301,7 +301,7 @@ def _parse_kwargs(self, user_kwargs: dict, check_envars: bool = False) -> tuple:
                     try:
                         # Parse env var if needed
                         run_env_value = literal_eval(run_env_value)  # type: ignore
-                    except ValueError:
+                    except (ValueError, SyntaxError):
                         pass
                     task_run_kwargs.update({key: run_env_value})
 


Test patch:
diff --git a/tests/agent/test_fargate_agent.py b/tests/agent/test_fargate_agent.py
--- a/tests/agent/test_fargate_agent.py
+++ b/tests/agent/test_fargate_agent.py
@@ -94,6 +94,24 @@ def test_parse_task_definition_kwargs(monkeypatch, runner_token):
     assert task_run_kwargs == {"placementConstraints": "test", "tags": "test"}
 
 
+def test_parse_task_definition_kwargs_errors(monkeypatch, runner_token):
+    boto3_client = MagicMock()
+    monkeypatch.setattr("boto3.client", boto3_client)
+
+    agent = FargateAgent()
+
+    kwarg_dict = {
+        "placementConstraints": "taskRoleArn='arn:aws:iam::543216789012:role/Dev",
+    }
+
+    task_definition_kwargs, task_run_kwargs = agent._parse_kwargs(kwarg_dict)
+
+    assert task_definition_kwargs == kwarg_dict
+    assert task_run_kwargs == {
+        "placementConstraints": "taskRoleArn='arn:aws:iam::543216789012:role/Dev"
+    }
+
+
 def test_parse_task_run_kwargs(monkeypatch, runner_token):
     boto3_client = MagicMock()
     monkeypatch.setattr("boto3.client", boto3_client)