Skip to content

Commit c8717ed

Browse files
antonisclaude
andcommitted
fix(test): use designated initializers for SentryException and SentryMessage
Warden flagged the migrated tests using `[SentryException alloc]` and `[SentryMessage alloc]` without `init`. Both classes have `SENTRY_NO_INIT` and require designated initializers (`initWithValue:type:` and `initWithFormatted:`), so the alloc-only pattern is undefined behavior — property assignments happened to work via zero-initialized memory but the test could crash or behave inconsistently and mask real regressions. The pattern was inherited from the original SentrySDKWrapper-based tests this PR migrated; same fix applied across all 12 occurrences. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c0a7243 commit c8717ed

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.m

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -834,8 +834,8 @@ - (void)testStartIgnoreErrorsDropsMatchingExceptionValue
834834
XCTAssertNotNil(options);
835835
XCTAssertNil(error);
836836
SentryEvent *event = [[SentryEvent alloc] init];
837-
SentryException *exception = [SentryException alloc];
838-
exception.value = @"IgnoreMe: This should be ignored";
837+
SentryException *exception =
838+
[[SentryException alloc] initWithValue:@"IgnoreMe: This should be ignored" type:nil];
839839
event.exceptions = @[ exception ];
840840
SentryEvent *result = options.beforeSend(event);
841841
XCTAssertNil(result, @"Event with matching exception.value should be dropped");
@@ -854,7 +854,8 @@ - (void)testStartIgnoreErrorsDropsMatchingEventMessage
854854
XCTAssertNotNil(options);
855855
XCTAssertNil(error);
856856
SentryEvent *event = [[SentryEvent alloc] init];
857-
SentryMessage *msg = [SentryMessage alloc];
857+
SentryMessage *msg =
858+
[[SentryMessage alloc] initWithFormatted:@"DropThisError: should be dropped"];
858859
msg.message = @"DropThisError: should be dropped";
859860
event.message = msg;
860861
SentryEvent *result = options.beforeSend(event);
@@ -874,10 +875,10 @@ - (void)testStartIgnoreErrorsDoesNotDropNonMatchingEvent
874875
XCTAssertNotNil(options);
875876
XCTAssertNil(error);
876877
SentryEvent *event = [[SentryEvent alloc] init];
877-
SentryException *exception = [SentryException alloc];
878-
exception.value = @"SomeOtherError: should not be ignored";
878+
SentryException *exception =
879+
[[SentryException alloc] initWithValue:@"SomeOtherError: should not be ignored" type:nil];
879880
event.exceptions = @[ exception ];
880-
SentryMessage *msg = [SentryMessage alloc];
881+
SentryMessage *msg = [[SentryMessage alloc] initWithFormatted:@"SomeOtherMessage"];
881882
msg.message = @"SomeOtherMessage";
882883
event.message = msg;
883884
SentryEvent *result = options.beforeSend(event);
@@ -897,7 +898,7 @@ - (void)testStartIgnoreErrorsDropsMatchingExactString
897898
XCTAssertNotNil(options);
898899
XCTAssertNil(error);
899900
SentryEvent *event = [[SentryEvent alloc] init];
900-
SentryMessage *msg = [SentryMessage alloc];
901+
SentryMessage *msg = [[SentryMessage alloc] initWithFormatted:@"ExactError"];
901902
msg.message = @"ExactError";
902903
event.message = msg;
903904
SentryEvent *result = options.beforeSend(event);
@@ -919,19 +920,19 @@ - (void)testStartIgnoreErrorsRegexAndStringBothWork
919920
XCTAssertNotNil(options);
920921
XCTAssertNil(error);
921922
SentryEvent *event1 = [[SentryEvent alloc] init];
922-
SentryException *exception = [SentryException alloc];
923-
exception.value = @"IgnoreMe: This should be ignored";
923+
SentryException *exception =
924+
[[SentryException alloc] initWithValue:@"IgnoreMe: This should be ignored" type:nil];
924925
event1.exceptions = @[ exception ];
925926
SentryEvent *result1 = options.beforeSend(event1);
926927
XCTAssertNil(result1, @"Event with matching regex should be dropped");
927928
SentryEvent *event2 = [[SentryEvent alloc] init];
928-
SentryMessage *msg = [SentryMessage alloc];
929+
SentryMessage *msg = [[SentryMessage alloc] initWithFormatted:@"ExactError"];
929930
msg.message = @"ExactError";
930931
event2.message = msg;
931932
SentryEvent *result2 = options.beforeSend(event2);
932933
XCTAssertNil(result2, @"Event with exactly matching string should be dropped");
933934
SentryEvent *event3 = [[SentryEvent alloc] init];
934-
SentryMessage *msg3 = [SentryMessage alloc];
935+
SentryMessage *msg3 = [[SentryMessage alloc] initWithFormatted:@"OtherError"];
935936
msg3.message = @"OtherError";
936937
event3.message = msg3;
937938
SentryEvent *result3 = options.beforeSend(event3);
@@ -954,9 +955,8 @@ - (void)testStartBeforeSendFiltersOutUnhandledJSException
954955
XCTAssertNil(error);
955956

956957
SentryEvent *event = [[SentryEvent alloc] init];
957-
SentryException *exception = [SentryException alloc];
958-
exception.type = @"Unhandled JS Exception";
959-
exception.value = @"Error: Test error";
958+
SentryException *exception = [[SentryException alloc] initWithValue:@"Error: Test error"
959+
type:@"Unhandled JS Exception"];
960960
event.exceptions = @[ exception ];
961961
SentryEvent *result = options.beforeSend(event);
962962
XCTAssertNil(result, @"Event with Unhandled JS Exception should be dropped");
@@ -976,29 +976,29 @@ - (void)testStartBeforeSendFiltersOutJSErrorCppException
976976
XCTAssertNil(error);
977977

978978
SentryEvent *event1 = [[SentryEvent alloc] init];
979-
SentryException *exception1 = [SentryException alloc];
980-
exception1.type = @"C++ Exception";
981-
exception1.value = @"N8facebook3jsi7JSErrorE: ExceptionsManager.reportException raised an "
982-
@"exception: Unhandled JS Exception: Error: Test error";
979+
SentryException *exception1 = [[SentryException alloc]
980+
initWithValue:@"N8facebook3jsi7JSErrorE: ExceptionsManager.reportException raised an "
981+
@"exception: Unhandled JS Exception: Error: Test error"
982+
type:@"C++ Exception"];
983983
event1.exceptions = @[ exception1 ];
984984
SentryEvent *result1 = options.beforeSend(event1);
985985
XCTAssertNil(
986986
result1, @"Event with ExceptionsManager.reportException in value should be dropped");
987987

988988
SentryEvent *event2 = [[SentryEvent alloc] init];
989-
SentryException *exception2 = [SentryException alloc];
990-
exception2.type = @"SomeOtherException";
991-
exception2.value = @"ExceptionsManager.reportException raised an exception: Unhandled JS "
992-
@"Exception: Error: Test";
989+
SentryException *exception2 = [[SentryException alloc]
990+
initWithValue:@"ExceptionsManager.reportException raised an exception: Unhandled JS "
991+
@"Exception: Error: Test"
992+
type:@"SomeOtherException"];
993993
event2.exceptions = @[ exception2 ];
994994
SentryEvent *result2 = options.beforeSend(event2);
995995
XCTAssertNil(
996996
result2, @"Event with ExceptionsManager.reportException in value should be dropped");
997997

998998
SentryEvent *event3 = [[SentryEvent alloc] init];
999-
SentryException *exception3 = [SentryException alloc];
1000-
exception3.type = @"C++ Exception";
1001-
exception3.value = @"std::runtime_error: Some other C++ error occurred";
999+
SentryException *exception3 =
1000+
[[SentryException alloc] initWithValue:@"std::runtime_error: Some other C++ error occurred"
1001+
type:@"C++ Exception"];
10021002
event3.exceptions = @[ exception3 ];
10031003
SentryEvent *result3 = options.beforeSend(event3);
10041004
XCTAssertNotNil(result3,

0 commit comments

Comments
 (0)