Browse Source

ref: remove expected_errors= from safe_execute (#71939)

this prevents it from being made typesafe (followup PR) -- fixed the one
user of this functionality to just use plain try/except

<!-- Describe your PR here. -->
anthony sottile 9 months ago
parent
commit
aa4b902492
3 changed files with 10 additions and 24 deletions
  1. 10 7
      src/sentry/tasks/post_process.py
  2. 0 4
      src/sentry/utils/safe.py
  3. 0 13
      tests/sentry/utils/test_safe.py

+ 10 - 7
src/sentry/tasks/post_process.py

@@ -1280,13 +1280,16 @@ def plugin_post_process_group(plugin_slug, event, **kwargs):
     from sentry.plugins.base import plugins
 
     plugin = plugins.get(plugin_slug)
-    safe_execute(
-        plugin.post_process,
-        event=event,
-        group=event.group,
-        expected_errors=(PluginError,),
-        **kwargs,
-    )
+    try:
+        plugin.post_process(
+            event=event,
+            group=event.group,
+            **kwargs,
+        )
+    except PluginError as e:
+        logger.info("post_process.process_error_ignored", extra={"exception": e})
+    except Exception as e:
+        logger.exception("post_process.process_error", extra={"exception": e})
 
 
 def feedback_filter_decorator(func):

+ 0 - 4
src/sentry/utils/safe.py

@@ -13,7 +13,6 @@ PathSearchable = Union[Mapping[str, Any], Sequence[Any], None]
 
 
 def safe_execute(func, *args, **kwargs):
-    expected_errors = kwargs.pop("expected_errors", None)
     try:
         result = func(*args, **kwargs)
     except Exception as e:
@@ -26,9 +25,6 @@ def safe_execute(func, *args, **kwargs):
         cls_name = cls.__name__
         logger = logging.getLogger(f"sentry.safe.{cls_name.lower()}")
 
-        if expected_errors and isinstance(e, expected_errors):
-            logger.info("%s.process_error_ignored", func_name, extra={"exception": e})
-            return
         logger.exception("%s.process_error", func_name, extra={"exception": e})
     else:
         return result

+ 0 - 13
tests/sentry/utils/test_safe.py

@@ -4,7 +4,6 @@ import unittest
 from collections.abc import MutableMapping
 from functools import partial
 from typing import Any
-from unittest.mock import Mock, patch
 
 import pytest
 
@@ -95,18 +94,6 @@ class SafeExecuteTest(TestCase):
 
         assert safe_execute(Foo().simple, 1) is None
 
-    @patch("sentry.utils.safe.logging.getLogger")
-    def test_with_expected_errors(self, mock_get_logger):
-        mock_log = Mock()
-        mock_get_logger.return_value = mock_log
-
-        def simple(a):
-            raise ValueError()
-
-        assert safe_execute(simple, 1, expected_errors=(ValueError,)) is None
-        assert mock_log.info.called
-        assert mock_log.error.called is False
-
 
 class GetPathTest(unittest.TestCase):
     def test_get_none(self):