Skip to content

Commit

Permalink
Experiment log routes handle missing log files
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckierDodge committed May 14, 2024
1 parent 13ff5c9 commit 8ee153e
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions wei/routers/experiment_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,24 @@
@router.get("/{experiment_id}/log")
async def log_return(experiment_id: str) -> str:
"""Returns the log for a given experiment"""
with open(
get_experiment_log_file(experiment_id),
"r",
) as f:
val = f.readlines()
logs = []
for entry in val:
try:
logs.append(json.loads(entry.split("(INFO):")[1].strip()))
except Exception as e:
print(e)
try:
experiment_log = get_experiment_log_file(experiment_id)
if experiment_log.exists():
with open(
get_experiment_log_file(experiment_id),
"r",
) as f:
val = f.readlines()
logs = []
for entry in val:
try:
logs.append(json.loads(entry.split("(INFO):")[1].strip()))
except Exception as e:
print(e)
else:
return JSONResponse({"error": "Log file not found"}, status_code=404)
except Exception as e:
return JSONResponse({"error": str(e)}, status_code=500)
return JSONResponse(logs)


Expand Down

0 comments on commit 8ee153e

Please sign in to comment.