Skip to content

Commit 89ef2bd

Browse files
authored
ref(aci): Remove a try/except block for more detailed errors (#111439)
# Description When investigating an issue, it was difficult to determine the source of the issue because we hit the exception block and lost which of the ValidationError was bubbling up. This will just allow the more specific validation error to bubble up and reformat them to all be ValidationErrors that can be handled in the API. The code still catches the exception and retriggers it to ensure the control flow is consistent and the validation error types are correct.
1 parent b3a1c72 commit 89ef2bd

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

src/sentry/incidents/metric_issue_detector.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from datetime import timedelta
22
from typing import Any
33

4+
from django.core.exceptions import ValidationError
5+
from parsimonious.exceptions import ParseError
46
from rest_framework import serializers
7+
from urllib3.exceptions import MaxRetryError, TimeoutError
58

69
from sentry import features, quotas
710
from sentry.constants import ObjectStatus
@@ -325,11 +328,9 @@ def update_data_source(
325328
validated_data_source: dict[str, Any] = {"data_sources": [data_source]}
326329
if not seer_updated:
327330
update_detector_data(instance, validated_data_source)
328-
except Exception:
331+
except (TimeoutError, MaxRetryError, ParseError, ValidationError) as e:
329332
# don't update the snuba query if we failed to send data to Seer
330-
raise serializers.ValidationError(
331-
"Failed to send data to Seer, cannot update detector"
332-
)
333+
raise serializers.ValidationError(str(e))
333334

334335
extrapolation_mode = format_extrapolation_mode(
335336
data_source.get("extrapolation_mode", snuba_query.extrapolation_mode)
@@ -367,11 +368,9 @@ def update_anomaly_detection(self, instance: Detector, validated_data: dict[str,
367368
try:
368369
update_detector_data(instance, validated_data)
369370
seer_updated = True
370-
except Exception:
371+
except (TimeoutError, MaxRetryError, ParseError, ValidationError) as e:
371372
# Don't update if we failed to send data to Seer
372-
raise serializers.ValidationError(
373-
"Failed to send data to Seer, cannot update detector"
374-
)
373+
raise serializers.ValidationError(str(e))
375374

376375
elif (
377376
validated_data.get("config")

0 commit comments

Comments
 (0)