Bug Fix: Handle possible null exceptions

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
Christopher Snowhill 2025-03-09 15:03:31 -07:00
parent f8ee7e5e46
commit cf77521bb7

View file

@ -404,7 +404,11 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
} }
@catch(NSException *e) { @catch(NSException *e) {
DLog(@"Exception caught while processing path: %@", e); DLog(@"Exception caught while processing path: %@", e);
[SentrySDK captureException:e]; if(e) {
[SentrySDK captureException:e];
} else {
[SentrySDK captureMessage:[NSString stringWithFormat:@"Null exception when processing path: %@", url]];
}
[pathTask finishWithStatus:kSentrySpanStatusInternalError]; [pathTask finishWithStatus:kSentrySpanStatusInternalError];
} }
@ -442,13 +446,14 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
[op addExecutionBlock:^{ [op addExecutionBlock:^{
id<SentrySpan> pathTask = nil; id<SentrySpan> pathTask = nil;
id<SentrySpan> innerTask = nil; id<SentrySpan> innerTask = nil;
NSURL *url = nil;
@try { @try {
if(containerTask) { if(containerTask) {
pathTask = [containerTask startChildWithOperation:@"Process path as container" description:[NSString stringWithFormat:@"Checking if file is container: %@", url]]; pathTask = [containerTask startChildWithOperation:@"Process path as container" description:[NSString stringWithFormat:@"Checking if file is container: %@", url]];
} }
[lock lock]; [lock lock];
NSURL *url = [expandedURLs objectAtIndex:0]; url = [expandedURLs objectAtIndex:0];
[expandedURLs removeObjectAtIndex:0]; [expandedURLs removeObjectAtIndex:0];
[lock unlock]; [lock unlock];
@ -520,7 +525,11 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
} }
@catch(NSException *e) { @catch(NSException *e) {
DLog(@"Exception caught while processing for containers: %@", e); DLog(@"Exception caught while processing for containers: %@", e);
[SentrySDK captureException:e]; if(e) {
[SentrySDK captureException:e];
} else {
[SentrySDK captureMessage:[NSString stringWithFormat:@"Null exception caught while processing containers for URL: %@", url]];
}
if(innerTask) { if(innerTask) {
[innerTask finishWithStatus:kSentrySpanStatusInternalError]; [innerTask finishWithStatus:kSentrySpanStatusInternalError];
} }
@ -554,6 +563,8 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
[self setProgressStatus:60.0]; [self setProgressStatus:60.0];
} }
NSArray *fileTypes = [AudioPlayer fileTypes];
id<SentrySpan> filterTask = [mainTask startChildWithOperation:@"Filtering URLs for dupes and supported tracks"]; id<SentrySpan> filterTask = [mainTask startChildWithOperation:@"Filtering URLs for dupes and supported tracks"];
// Deduplication of contained URLs // Deduplication of contained URLs
@ -589,7 +600,7 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
NSString *ext = [[url pathExtension] lowercaseString]; NSString *ext = [[url pathExtension] lowercaseString];
// Need a better way to determine acceptable file types than basing it on extensions. // Need a better way to determine acceptable file types than basing it on extensions.
if([url isFileURL] && ![[AudioPlayer fileTypes] containsObject:ext]) if([url isFileURL] && ![fileTypes containsObject:ext])
continue; continue;
if(![uniqueURLs containsObject:url]) { if(![uniqueURLs containsObject:url]) {
@ -602,7 +613,11 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
} }
@catch(NSException *e) { @catch(NSException *e) {
DLog(@"Exception caught while filtering paths: %@", e); DLog(@"Exception caught while filtering paths: %@", e);
[SentrySDK captureException:e]; if(e) {
[SentrySDK captureException:e];
} else {
[SentrySDK captureMessage:[NSString stringWithFormat:@"Null exception caught when filtering paths for URL: %@", url]];
}
if(fileTask) { if(fileTask) {
[fileTask finishWithStatus:kSentrySpanStatusInternalError]; [fileTask finishWithStatus:kSentrySpanStatusInternalError];
} }
@ -646,7 +661,7 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
} }
// Need a better way to determine acceptable file types than basing it on extensions. // Need a better way to determine acceptable file types than basing it on extensions.
if([url isFileURL] && ![[AudioPlayer fileTypes] containsObject:[[url pathExtension] lowercaseString]]) { if([url isFileURL] && ![fileTypes containsObject:[[url pathExtension] lowercaseString]]) {
[containedUrlTask finish]; [containedUrlTask finish];
continue; continue;
} }
@ -659,7 +674,11 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
} }
@catch(NSException *e) { @catch(NSException *e) {
DLog(@"Exception caught filtering contained URL: %@", e); DLog(@"Exception caught filtering contained URL: %@", e);
[SentrySDK captureException:e]; if(e) {
[SentrySDK captureException:e];
} else {
[SentrySDK captureMessage:[NSString stringWithFormat:@"Null exception caught when filtering contained URL: %@", url]];
}
if(containedUrlTask) { if(containedUrlTask) {
[containedUrlTask finishWithStatus:kSentrySpanStatusInternalError]; [containedUrlTask finishWithStatus:kSentrySpanStatusInternalError];
} }
@ -1076,7 +1095,11 @@ NSURL *_Nullable urlForPath(NSString *_Nullable path);
} }
@catch(NSException *e) { @catch(NSException *e) {
DLog(@"Exception thrown while reading tag synchronously: %@", e); DLog(@"Exception thrown while reading tag synchronously: %@", e);
[SentrySDK captureException:e]; if(e) {
[SentrySDK captureException:e];
} else {
[SentrySDK captureMessage:[NSString stringWithFormat:@"Null exception caught while reading tags for URL: %@", pe.url]];
}
if(childTask) { if(childTask) {
[childTask finishWithStatus:kSentrySpanStatusInternalError]; [childTask finishWithStatus:kSentrySpanStatusInternalError];
} }