Add error handling for JSON serialization failures

- Wrap json.dumps() in try-catch block to handle JSONEncodeError
- Raise RuntimeError with descriptive message for serialization failures
- Addresses PR review feedback for better fault tolerance

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2025-06-01 06:58:27 +00:00
parent bcc77cb831
commit c1eb48bd6e

View File

@@ -90,6 +90,7 @@ class SQLiteFlowPersistence(FlowPersistence):
f"state_data must be either a Pydantic BaseModel or dict, got {type(state_data)}"
)
try:
with sqlite3.connect(self.db_path) as conn:
conn.execute(
"""
@@ -107,6 +108,8 @@ class SQLiteFlowPersistence(FlowPersistence):
json.dumps(state_dict, cls=CrewJSONEncoder),
),
)
except json.JSONEncodeError as e:
raise RuntimeError(f"Failed to serialize flow state: {str(e)}") from e
def load_state(self, flow_uuid: str) -> Optional[Dict[str, Any]]:
"""Load the most recent state for a given flow UUID.