From ed71afe442356e91e54a560aff8d0b08e809f5d2 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 3 May 2026 21:44:55 +0000 Subject: [PATCH] fix(simulation): add FileNotFoundError check in delete_agent_profile and endpoint --- backend/app/api/simulation.py | 2 ++ backend/app/services/simulation_manager.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/backend/app/api/simulation.py b/backend/app/api/simulation.py index f803a36f..64731222 100644 --- a/backend/app/api/simulation.py +++ b/backend/app/api/simulation.py @@ -2743,6 +2743,8 @@ def delete_agent(simulation_id: str, user_id: int): return jsonify({"success": False, "error": str(e)}), 403 except LookupError as e: return jsonify({"success": False, "error": str(e)}), 404 + except FileNotFoundError as e: + return jsonify({"success": False, "error": str(e)}), 404 return jsonify({"success": True, "data": {"deleted_user_id": user_id}}) except Exception as e: diff --git a/backend/app/services/simulation_manager.py b/backend/app/services/simulation_manager.py index fe769cc3..8fee0992 100644 --- a/backend/app/services/simulation_manager.py +++ b/backend/app/services/simulation_manager.py @@ -614,6 +614,9 @@ class SimulationManager: profiles_file = os.path.join(sim_dir, "reddit_profiles.json") backup_file = profiles_file + ".bak" + if not os.path.exists(profiles_file): + raise FileNotFoundError(f"reddit_profiles.json not found for {simulation_id}") + with open(profiles_file, 'r', encoding='utf-8') as f: profiles = json.load(f)