Skip to content

Commit 42a68cd

Browse files
fix ios tests and fix some logic issues
1 parent 8ae5aea commit 42a68cd

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.mm

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -506,13 +506,13 @@ - (void)testIgnoreErrorsDropsMatchingExceptionValue
506506
NSError *error = nil;
507507
NSDictionary *mockedOptions = @{
508508
@"dsn" : @"https://[email protected]/1234567",
509-
@"ignoreErrors" : @[ @"IgnoreMe.*" ]
509+
@"ignoreErrorsRegex" : @[ @"IgnoreMe.*" ]
510510
};
511511
SentryOptions *options = [rnSentry createOptionsWithDictionary:mockedOptions error:&error];
512512
XCTAssertNotNil(options);
513513
XCTAssertNil(error);
514514
SentryEvent *event = [[SentryEvent alloc] init];
515-
SentryException *exception = [[SentryException alloc] init];
515+
SentryException *exception = [SentryException alloc];
516516
exception.value = @"IgnoreMe: This should be ignored";
517517
event.exceptions = @[ exception ];
518518
SentryEvent *result = options.beforeSend(event);
@@ -525,14 +525,14 @@ - (void)testIgnoreErrorsDropsMatchingEventMessage
525525
NSError *error = nil;
526526
NSDictionary *mockedOptions = @{
527527
@"dsn" : @"https://[email protected]/1234567",
528-
@"ignoreErrors" : @[ @"DropThisError" ]
528+
@"ignoreErrorsStr" : @[ @"DropThisError" ]
529529
};
530530
SentryOptions *options = [rnSentry createOptionsWithDictionary:mockedOptions error:&error];
531531
XCTAssertNotNil(options);
532532
XCTAssertNil(error);
533533
SentryEvent *event = [[SentryEvent alloc] init];
534-
SentryMessage *msg = [[SentryMessage alloc] init];
535-
msg.formatted = @"DropThisError: should be dropped";
534+
SentryMessage *msg = [SentryMessage alloc] ;
535+
msg.message = @"DropThisError: should be dropped";
536536
event.message = msg;
537537
SentryEvent *result = options.beforeSend(event);
538538
XCTAssertNil(result, @"Event with matching event.message.formatted should be dropped");
@@ -544,17 +544,17 @@ - (void)testIgnoreErrorsDoesNotDropNonMatchingEvent
544544
NSError *error = nil;
545545
NSDictionary *mockedOptions = @{
546546
@"dsn" : @"https://[email protected]/1234567",
547-
@"ignoreErrors" : @[ @"IgnoreMe.*" ]
547+
@"ignoreErrorsRegex" : @[ @"IgnoreMe.*" ]
548548
};
549549
SentryOptions *options = [rnSentry createOptionsWithDictionary:mockedOptions error:&error];
550550
XCTAssertNotNil(options);
551551
XCTAssertNil(error);
552552
SentryEvent *event = [[SentryEvent alloc] init];
553-
SentryException *exception = [[SentryException alloc] init];
553+
SentryException *exception = [SentryException alloc];
554554
exception.value = @"SomeOtherError: should not be ignored";
555555
event.exceptions = @[ exception ];
556-
SentryMessage *msg = [[SentryMessage alloc] init];
557-
msg.formatted = @"SomeOtherMessage";
556+
SentryMessage *msg = [SentryMessage alloc];
557+
msg.message = @"SomeOtherMessage";
558558
event.message = msg;
559559
SentryEvent *result = options.beforeSend(event);
560560
XCTAssertNotNil(result, @"Event with non-matching error should not be dropped");
@@ -566,14 +566,14 @@ - (void)testIgnoreErrorsDropsMatchingExactString
566566
NSError *error = nil;
567567
NSDictionary *mockedOptions = @{
568568
@"dsn" : @"https://[email protected]/1234567",
569-
@"ignoreErrors" : @[ @"ExactError" ]
569+
@"ignoreErrorsStr" : @[ @"ExactError" ]
570570
};
571571
SentryOptions *options = [rnSentry createOptionsWithDictionary:mockedOptions error:&error];
572572
XCTAssertNotNil(options);
573573
XCTAssertNil(error);
574574
SentryEvent *event = [[SentryEvent alloc] init];
575-
SentryMessage *msg = [[SentryMessage alloc] init];
576-
msg.formatted = @"ExactError";
575+
SentryMessage *msg = [SentryMessage alloc];
576+
msg.message = @"ExactError";
577577
event.message = msg;
578578
SentryEvent *result = options.beforeSend(event);
579579
XCTAssertNil(result, @"Event with exactly matching string should be dropped");
@@ -585,29 +585,31 @@ - (void)testIgnoreErrorsRegexAndStringBothWork
585585
NSError *error = nil;
586586
NSDictionary *mockedOptions = @{
587587
@"dsn" : @"https://[email protected]/1234567",
588-
@"ignoreErrors" : @[ @"ExactError", @"IgnoreMe.*" ]
588+
@"ignoreErrorsStr" : @[ @"ExactError" ],
589+
@"ignoreErrorsRegex" : @[ @"IgnoreMe.*" ],
590+
589591
};
590592
SentryOptions *options = [rnSentry createOptionsWithDictionary:mockedOptions error:&error];
591593
XCTAssertNotNil(options);
592594
XCTAssertNil(error);
593595
// Test regex match
594596
SentryEvent *event1 = [[SentryEvent alloc] init];
595-
SentryException *exception = [[SentryException alloc] init];
597+
SentryException *exception = [SentryException alloc];
596598
exception.value = @"IgnoreMe: This should be ignored";
597599
event1.exceptions = @[ exception ];
598600
SentryEvent *result1 = options.beforeSend(event1);
599601
XCTAssertNil(result1, @"Event with matching regex should be dropped");
600602
// Test exact string match
601603
SentryEvent *event2 = [[SentryEvent alloc] init];
602-
SentryMessage *msg = [[SentryMessage alloc] init];
603-
msg.formatted = @"ExactError";
604+
SentryMessage *msg = [SentryMessage alloc];
605+
msg.message = @"ExactError";
604606
event2.message = msg;
605607
SentryEvent *result2 = options.beforeSend(event2);
606608
XCTAssertNil(result2, @"Event with exactly matching string should be dropped");
607609
// Test non-matching
608610
SentryEvent *event3 = [[SentryEvent alloc] init];
609-
SentryMessage *msg3 = [[SentryMessage alloc] init];
610-
msg3.formatted = @"OtherError";
611+
SentryMessage *msg3 = [SentryMessage alloc];
612+
msg3.message = @"OtherError";
611613
event3.message = msg3;
612614
SentryEvent *result3 = options.beforeSend(event3);
613615
XCTAssertNotNil(result3, @"Event with non-matching error should not be dropped");

packages/core/ios/RNSentry.mm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,20 @@ - (BOOL)shouldIgnoreError:(NSString *)message
182182
if ((!_ignoreErrorPatternsStr && !_ignoreErrorPatternsRegex) || !message) {
183183
return NO;
184184
}
185-
185+
186186
for (NSRegularExpression *regex in _ignoreErrorPatternsRegex) {
187187
NSRange range = NSMakeRange(0, message.length);
188188
if ([regex firstMatchInString:message options:0 range:range]) {
189189
return YES;
190190
}
191191
}
192-
return NO;
193-
192+
194193
for (NSString *str in _ignoreErrorPatternsStr) {
195194
if ([message containsString:str]) {
196195
return YES;
197196
}
198197
}
198+
return NO;
199199
}
200200

201201
- (SentryOptions *_Nullable)createOptionsWithDictionary:(NSDictionary *_Nonnull)options
@@ -207,18 +207,18 @@ - (SentryOptions *_Nullable)createOptionsWithDictionary:(NSDictionary *_Nonnull)
207207
// react native Because we sent it already before the app crashed.
208208
if (nil != event.exceptions.firstObject.type &&
209209
[event.exceptions.firstObject.type rangeOfString:@"Unhandled JS Exception"].location
210-
!= NSNotFound) {
210+
!= NSNotFound) {
211211
return nil;
212212
}
213-
213+
214214
// Regex and Str are set when one of them has value so we only need to check one of them.
215-
if (self->_ignoreErrorPatternsStr) {
215+
if (self->_ignoreErrorPatternsStr || self->_ignoreErrorPatternsRegex) {
216216
for (SentryException *exception in event.exceptions) {
217217
if ([self shouldIgnoreError:exception.value]) {
218218
return nil;
219219
}
220220
}
221-
if ([self shouldIgnoreError:event.message.formatted]) {
221+
if ([self shouldIgnoreError:event.message.message]) {
222222
return nil;
223223
}
224224
}

0 commit comments

Comments
 (0)