Skip to content

Commit

Permalink
ref: Improve FileManager delete logs (#3514)
Browse files Browse the repository at this point in the history
Delete file log messages show whether a file was successfully deleted,
it doesn't exist, or an error occurred.

Co-authored-by: Karl Heinz Struggl <[email protected]>
Co-authored-by: Sentry Github Bot <[email protected]>
  • Loading branch information
3 people authored Dec 19, 2023
1 parent fac579e commit add9550
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Sources/Sentry/SentryFileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,15 @@ - (void)removeFileAtPath:(NSString *)path
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error = nil;
@synchronized(self) {
SENTRY_LOG_DEBUG(@"Deleting %@", path);

if (![fileManager removeItemAtPath:path error:&error]) {
// We don't want to log an error if the file doesn't exist.
if (error.code != NSFileNoSuchFileError) {
SENTRY_LOG_ERROR(@"Couldn't delete file %@: %@", path, error);
if (error.code == NSFileNoSuchFileError) {
SENTRY_LOG_DEBUG(@"No file to delete at %@", path);
} else {
SENTRY_LOG_ERROR(
@"Error occurred while deleting file at %@ because of %@", path, error);
}
} else {
SENTRY_LOG_DEBUG(@"Successfully deleted file at %@", path);
}
}
}
Expand Down

0 comments on commit add9550

Please sign in to comment.