Browse Source

fix(mobile): Elide invalid_data errors from Cocoa in the UI (#50952)

### Summary
Don't show the invalid_data errors in the UI as to not cause false alarm
as this has since been fixed.


### Screenshots

#### Before
![Screenshot 2023-06-14 at 12 08 45
PM](https://github.com/getsentry/sentry/assets/6111995/ccbef4f6-023e-4e1c-80cb-921f7d68ea55)

#### After
![Screenshot 2023-06-14 at 12 04 51
PM](https://github.com/getsentry/sentry/assets/6111995/24582d7a-058e-4b00-9740-9c88f1f513f6)

---------

Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
Kev 1 year ago
parent
commit
0fa56f929a

+ 32 - 0
static/app/components/events/eventErrors.spec.tsx

@@ -56,6 +56,38 @@ describe('EventErrors', () => {
     ).toBeInTheDocument();
   });
 
+  it('does not render hidden cocoa errors', async () => {
+    const eventWithErrors = TestStubs.Event({
+      errors: [
+        {
+          type: 'not_invalid_data',
+          data: {
+            name: 'logentry',
+          },
+          message: 'no message present',
+        },
+        {
+          type: 'invalid_data',
+          data: {
+            name: 'contexts.trace.sampled',
+          },
+          message: 'expected an object',
+        },
+      ],
+      sdk: {
+        name: 'sentry.cocoa',
+        version: '8.7.3',
+      },
+    });
+
+    render(<EventErrors {...defaultProps} event={eventWithErrors} />);
+
+    await userEvent.click(screen.getByText(/there was 1 problem processing this event/i));
+    const errorItem = screen.getByTestId('event-error-item');
+    expect(errorItem).toBeInTheDocument();
+    expect(within(errorItem).getByText('logentry')).toBeInTheDocument();
+  });
+
   it('hides source map not found error', () => {
     const eventWithDifferentDist = TestStubs.Event({
       errors: [

+ 23 - 3
static/app/components/events/eventErrors.tsx

@@ -10,7 +10,10 @@ import findBestThread from 'sentry/components/events/interfaces/threads/threadSe
 import getThreadException from 'sentry/components/events/interfaces/threads/threadSelector/getThreadException';
 import ExternalLink from 'sentry/components/links/externalLink';
 import List from 'sentry/components/list';
-import {JavascriptProcessingErrors} from 'sentry/constants/eventErrors';
+import {
+  CocoaProcessingErrors,
+  JavascriptProcessingErrors,
+} from 'sentry/constants/eventErrors';
 import {tct, tn} from 'sentry/locale';
 import {space} from 'sentry/styles/space';
 import {Project} from 'sentry/types';
@@ -21,6 +24,7 @@ import {defined} from 'sentry/utils';
 import {trackAnalytics} from 'sentry/utils/analytics';
 import {useApiQuery} from 'sentry/utils/queryClient';
 import useOrganization from 'sentry/utils/useOrganization';
+import {semverCompare} from 'sentry/utils/versions';
 import {projectProcessingIssuesMessages} from 'sentry/views/settings/project/projectProcessingIssues';
 
 import {DataSection} from './styles';
@@ -45,6 +49,22 @@ function isDataMinified(str: string | null) {
   return !![...str.matchAll(MINIFIED_DATA_JAVA_EVENT_REGEX_MATCH)].length;
 }
 
+function shouldErrorBeShown(error: EventErrorData, event: Event) {
+  if (ERRORS_TO_HIDE.includes(error.type as JavascriptProcessingErrors)) {
+    return false;
+  }
+  if (
+    error.type === CocoaProcessingErrors.COCOA_INVALID_DATA &&
+    event.sdk?.name === 'sentry.cocoa' &&
+    error.data?.name === 'contexts.trace.sampled' &&
+    semverCompare(event.sdk?.version || '', '8.7.4') === -1
+  ) {
+    // The Cocoa SDK sends wrong values for contexts.trace.sampled before 8.7.4
+    return false;
+  }
+  return true;
+}
+
 const hasThreadOrExceptionMinifiedFrameData = (
   definedEvent: Event,
   bestThread?: Thread
@@ -240,8 +260,8 @@ export function EventErrors({event, project, isShare}: EventErrorsProps) {
   const otherErrors: Array<EventErrorData> =
     eventErrors.length > MAX_ERRORS ? eventErrors : uniqWith(eventErrors, isEqual);
 
-  const errors = [...otherErrors, ...proguardErrors].filter(
-    error => !ERRORS_TO_HIDE.includes(error.type as JavascriptProcessingErrors)
+  const errors = [...otherErrors, ...proguardErrors].filter(e =>
+    shouldErrorBeShown(e, event)
   );
 
   if (proguardErrorsLoading) {

+ 4 - 0
static/app/constants/eventErrors.tsx

@@ -11,3 +11,7 @@ export enum JavascriptProcessingErrors {
   JS_TOO_LARGE = 'js_too_large',
   JS_FETCH_TIMEOUT = 'js_fetch_timeout',
 }
+
+export enum CocoaProcessingErrors {
+  COCOA_INVALID_DATA = 'invalid_data',
+}