Browse Source

Semi support malformed incoming event exception values that aren't
strings

David Burke 4 years ago
parent
commit
66292de7f9
2 changed files with 13 additions and 1 deletions
  1. 7 0
      events/tests/tests.py
  2. 6 1
      sentry/eventtypes/error.py

+ 7 - 0
events/tests/tests.py

@@ -252,3 +252,10 @@ class EventStoreTestCase(APITestCase):
             self.assertNotIn("this is invalid", tag)
         self.assertEqual(len(event_json.get("errors")), 1)
 
+    def test_malformed_exception_value(self):
+        """ Malformed exception values aren't 100% supported, but should stored anyway """
+        with open("events/test_data/py_error.json") as json_file:
+            data = json.load(json_file)
+        data["exception"]["values"][0]["value"] = {"why is this": "any object?"}
+        res = self.client.post(self.url, data, format="json")
+        self.assertEqual(res.status_code, 200)

+ 6 - 1
sentry/eventtypes/error.py

@@ -57,7 +57,12 @@ class ErrorEvent(BaseEvent):
             return metadata.get("function") or "<unknown>"
         if not metadata.get("value"):
             return ty
-        return u"{}: {}".format(ty, truncatechars(metadata["value"].splitlines()[0]))
+        try:
+            return "{}: {}".format(ty, truncatechars(metadata["value"].splitlines()[0]))
+        except AttributeError:
+            # GlitchTip modification
+            # Exception value is specified as a string, sometimes it isn't. This is a fallback.
+            return "{}: {}".format(ty, str(metadata["value"]))
 
     def get_location(self, data):
         return force_text(