Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ def get(self, request: Request, organization: Organization) -> Response:
timeout=SEER_TIMEOUT_S,
retries=SEER_RETRIES,
)
response_data = response.json()
except Exception:
logger.exception("Seer failed to generate user feedback label groups")
return Response(
Expand All @@ -233,7 +232,7 @@ def get(self, request: Request, organization: Organization) -> Response:
return Response(
{"detail": "Failed to generate user feedback label groups"}, status=500
)
label_groups = response_data["data"]
label_groups = response.json()["data"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: JSON data errors now unhandled.

Moving response.json()["data"] outside the try/except block means JSON parsing or key access errors will raise an unhandled exception instead of being caught and returning the intended 500 error response with proper logging. Previously these errors were caught by the exception handler at lines 222-225.

Fix in Cursor Fix in Web

else:
# If there are less than THRESHOLD_TO_GET_ASSOCIATED_LABELS feedbacks, we don't ask for associated labels
# The more feedbacks there are, the LLM does a better job of generating associated labels since it has more context
Expand Down
5 changes: 1 addition & 4 deletions src/sentry/feedback/usecases/label_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def generate_labels(feedback_message: str, organization_id: int) -> list[str]:
timeout=SEER_TIMEOUT_S,
retries=SEER_RETRIES,
)
response_data = response.json()
except Exception:
logger.exception("Seer failed to generate user feedback labels")
raise
Expand All @@ -58,7 +57,5 @@ def generate_labels(feedback_message: str, organization_id: int) -> list[str]:
)
raise Exception("Seer returned non-200 response")

labels = response_data["data"]["labels"]

# Guaranteed to be a list of strings (validated in Seer)
return labels
return response.json()["data"]["labels"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Error Handling Removes Vital Debugging Context

Moving response.json()["data"]["labels"] outside the try/except block means JSON parsing or key access errors will now raise without the contextual logging that previously occurred. Before, such failures were logged with "Seer failed to generate user feedback labels" before re-raising, providing important debugging context that is now lost.

Fix in Cursor Fix in Web

2 changes: 1 addition & 1 deletion src/sentry/feedback/usecases/spam_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def is_spam_seer(message: str, organization_id: int) -> bool | None:
timeout=SEER_TIMEOUT_S,
retries=SEER_RETRIES,
)
response_data = response.json()
except Exception:
logger.exception("Seer failed to check if message is spam")
return None
Expand All @@ -47,6 +46,7 @@ def is_spam_seer(message: str, organization_id: int) -> bool | None:
)
return None

response_data = response.json()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unhandled JSON Errors Violate Contract

Moving response.json() outside the try/except block means JSON parsing errors will now raise an unhandled exception instead of returning None as documented. The function's contract states it "Returns None if the request fails", but a JSONDecodeError will now propagate to callers instead of being gracefully handled.

Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... Should I wrap all the response.json() in their own try/catch??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo we shouldnt do more try catches. We've been trying to move away from the blanket exc handlers when making seer requests, endpoints have their own handlers that should work fine

if (
not isinstance(response_data, dict)
or "is_spam" not in response_data
Expand Down
3 changes: 1 addition & 2 deletions src/sentry/feedback/usecases/title_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def get_feedback_title_from_seer(feedback_message: str, organization_id: int) ->
timeout=SEER_TIMEOUT_S,
retries=SEER_RETRIES,
)
response_data = response.json()
except Exception:
return None

Expand All @@ -93,7 +92,7 @@ def get_feedback_title_from_seer(feedback_message: str, organization_id: int) ->
return None

try:
return response_data["title"].strip() or None
return response.json()["title"].strip() or None
except Exception:
return None

Expand Down
Loading