debug: comprehensive error handling and logging for list_goals
All checks were successful
Deploy Development / deploy (push) Successful in 45s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s

- try-catch around entire endpoint
- try-catch for each goal progress update
- Detailed error logging with traceback
- Continue processing other goals if one fails
- Clear error message to frontend

This will show exact error location in logs.
This commit is contained in:
Lars 2026-03-27 07:58:56 +01:00
parent 1f4ee5021e
commit 210671059a

View File

@ -161,27 +161,42 @@ def list_goals(session: dict = Depends(require_auth)):
"""List all goals for current user""" """List all goals for current user"""
pid = session['profile_id'] pid = session['profile_id']
with get_db() as conn: try:
cur = get_cursor(conn) with get_db() as conn:
cur.execute(""" cur = get_cursor(conn)
SELECT id, goal_type, is_primary, status, cur.execute("""
target_value, current_value, start_value, unit, SELECT id, goal_type, is_primary, status,
start_date, target_date, reached_date, target_value, current_value, start_value, unit,
name, description, start_date, target_date, reached_date,
progress_pct, projection_date, on_track, name, description,
created_at, updated_at progress_pct, projection_date, on_track,
FROM goals created_at, updated_at
WHERE profile_id = %s FROM goals
ORDER BY is_primary DESC, created_at DESC WHERE profile_id = %s
""", (pid,)) ORDER BY is_primary DESC, created_at DESC
""", (pid,))
goals = [r2d(row) for row in cur.fetchall()] goals = [r2d(row) for row in cur.fetchall()]
print(f"[DEBUG] Loaded {len(goals)} goals for profile {pid}")
# Update current values for each goal # Update current values for each goal
for goal in goals: for goal in goals:
_update_goal_progress(conn, pid, goal) try:
_update_goal_progress(conn, pid, goal)
except Exception as e:
print(f"[ERROR] Failed to update progress for goal {goal.get('id')}: {e}")
# Continue with other goals even if one fails
return goals return goals
except Exception as e:
print(f"[ERROR] list_goals failed: {e}")
import traceback
traceback.print_exc()
raise HTTPException(
status_code=500,
detail=f"Fehler beim Laden der Ziele: {str(e)}"
)
@router.post("/create") @router.post("/create")
def create_goal(data: GoalCreate, session: dict = Depends(require_auth)): def create_goal(data: GoalCreate, session: dict = Depends(require_auth)):