File tree Expand file tree Collapse file tree 7 files changed +22
-28
lines changed
Branch-TestBed/Branch-SDK-Tests Expand file tree Collapse file tree 7 files changed +22
-28
lines changed Original file line number Diff line number Diff line change @@ -250,19 +250,12 @@ - (void)testLogFormat_includeCallerDetailsNO_NSError {
250250}
251251
252252- (void )testDefaultBranchLogFormat {
253- __block NSError *originalError = [NSError errorWithDomain: @" com.domain.test" code: 200 userInfo: @{@" Error Message" : @" Test Error" }];
253+ NSError *error = [NSError errorWithDomain: @" com.domain.test" code: 200 userInfo: @{@" Error Message" : @" Test Error" }];
254254
255- BranchLogger *logger = [BranchLogger new ];
256- logger.loggingEnabled = YES ;
257-
258- logger.logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) {
259- NSString *expectedMessage = @" [BranchSDK][Error][BranchLoggerTests testDefaultBranchLogFormat] msg NSError: The operation couldn’t be completed. (com.domain.test error 200.)" ;
260- NSString *formattedMessage = [BranchLogger formatMessage: message logLevel: logLevel error: error];
261-
262- XCTAssertTrue ([expectedMessage isEqualToString: formattedMessage]);
263- };
255+ NSString *expectedMessage = @" [BranchSDK][Error]msg NSError: Error Domain=com.domain.test Code=200 \" (null)\" UserInfo={Error Message=Test Error}" ;
256+ NSString *formattedMessage = [BranchLogger formatMessage: @" msg" logLevel: BranchLogLevelError error: error];
264257
265- [logger logError: @" msg " error: originalError] ;
258+ XCTAssertTrue ([expectedMessage isEqualToString: formattedMessage]) ;
266259}
267260
268261@end
Original file line number Diff line number Diff line change @@ -462,6 +462,8 @@ + (NSData *)dataFromHexString:(NSString*)string {
462462 data = [NSData dataWithBytes: bytes length: b-bytes];
463463 }
464464
465+ // Error handling in C code is one case where goto can improve readability.
466+ // https://www.kernel.org/doc/html/v4.19/process/coding-style.html
465467exit:
466468 if (bytes) {
467469 free (bytes);
Original file line number Diff line number Diff line change @@ -68,8 +68,7 @@ + (NSDate *)retrieveDateForService:(NSString *)service key:(NSString *)key error
6868 if (valueData) {
6969 @try {
7070 value = [NSKeyedUnarchiver unarchivedObjectOfClass: [NSDate class ] fromData: (__bridge NSData *)valueData error: NULL ];
71- }
72- @catch (id ) {
71+ } @catch (NSException *exception) {
7372 value = nil ;
7473 NSError *localError = [self errorWithKey: key OSStatus: errSecDecode];
7574 if (error) *error = localError;
@@ -91,8 +90,7 @@ + (NSError *) storeDate:(NSDate *)date
9190 NSData * valueData = nil ;
9291 @try {
9392 valueData = [NSKeyedArchiver archivedDataWithRootObject: date requiringSecureCoding: YES error: NULL ];
94- }
95- @catch (id ) {
93+ } @catch (NSException *exception) {
9694 valueData = nil ;
9795 }
9896 if (!valueData) {
Original file line number Diff line number Diff line change @@ -52,9 +52,7 @@ - (NSString*) description {
5252 int e = errno;
5353 [[BranchLogger shared ] logWarning: [NSString stringWithFormat: @" Failed to read IP Address: (%d ): %s " , e, strerror (e)] error: nil ];
5454
55- // Error handling in C code is one case where goto can improve readability.
56- // https://www.kernel.org/doc/html/v4.19/process/coding-style.html
57- goto err_free_interfaces;
55+ goto exit;
5856 }
5957
6058 // Loop through linked list of interfaces --
@@ -96,7 +94,9 @@ - (NSString*) description {
9694 }
9795 }
9896
99- err_free_interfaces:
97+ // Error handling in C code is one case where goto can improve readability.
98+ // https://www.kernel.org/doc/html/v4.19/process/coding-style.html
99+ exit:
100100 if (interfaces) freeifaddrs (interfaces);
101101 return currentInterfaces;
102102}
Original file line number Diff line number Diff line change @@ -937,8 +937,8 @@ - (NSData *)serializePrefDict:(NSMutableDictionary *)dict {
937937 NSData *data = nil ;
938938 @try {
939939 data = [NSKeyedArchiver archivedDataWithRootObject: dict requiringSecureCoding: YES error: NULL ];
940- } @catch (id exception) {
941- [[BranchLogger shared ] logWarning : [NSString stringWithFormat: @" Exception serializing preferences dict: %@ ." , exception] error: nil ];
940+ } @catch (NSException * exception) {
941+ [[BranchLogger shared ] logError : [NSString stringWithFormat: @" Exception serializing preferences dict: %@ ." , exception] error: nil ];
942942 }
943943 return data;
944944}
@@ -971,8 +971,8 @@ - (NSData *)loadPrefData {
971971 if (error || !data) {
972972 [[BranchLogger shared ] logWarning: @" Failed to load preferences from storage. This is expected on first run." error: error];
973973 }
974- } @catch (NSException *) {
975- [[BranchLogger shared ] logWarning: @" Failed to load preferences from storage. " error: nil ];
974+ } @catch (NSException *exception ) {
975+ [[BranchLogger shared ] logError: [ NSString stringWithFormat: @" Exception loading preferences dict: %@ . " , exception] error: nil ];
976976 }
977977 return data;
978978}
Original file line number Diff line number Diff line change @@ -197,11 +197,12 @@ - (void) presentActivityViewControllerFromViewController:(UIViewController*_Null
197197 NSString *emailSubject = self.linkProperties .controlParams [BRANCH_LINK_DATA_KEY_EMAIL_SUBJECT];
198198 if (emailSubject.length <= 0 ) emailSubject = self.emailSubject ;
199199 if (emailSubject.length ) {
200+ // Key value coding to set email subject
201+ // https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/KeyValueCoding/SearchImplementation.html#//apple_ref/doc/uid/20000955
200202 @try {
201203 [shareViewController setValue: emailSubject forKey: @" subject" ];
202- }
203- @catch (NSException *) {
204- [[BranchLogger shared ] logWarning: @" Unable to setValue 'emailSubject' forKey 'subject' on UIActivityViewController." error: nil ];
204+ } @catch (NSException *exception) {
205+ [[BranchLogger shared ] logWarning: [NSString stringWithFormat: @" Exception to setValue 'emailSubject' forKey 'subject' on UIActivityViewController: %@ ." , exception] error: nil ];
205206 }
206207 }
207208
Original file line number Diff line number Diff line change 1111typedef NS_ENUM (NSUInteger , BranchLogLevel) {
1212 BranchLogLevelVerbose, // development
1313 BranchLogLevelDebug, // validation and troubleshooting
14- BranchLogLevelWarning, // potential errors and attempts at recovery
15- BranchLogLevelError, // unexpected or unhandled errors
14+ BranchLogLevelWarning, // potential errors and attempts at recovery. SDK may be in a bad state.
15+ BranchLogLevelError, // severe errors. SDK is probably in a bad state.
1616};
1717
1818typedef void (^BranchLogCallback)(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error);
You can’t perform that action at this time.
0 commit comments