Skip to content

Commit

Permalink
Merge f679404 into 72e34fa
Browse files Browse the repository at this point in the history
  • Loading branch information
philprime authored Jan 14, 2025
2 parents 72e34fa + f679404 commit 39c747b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 19 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- Add protocol for custom screenName for UIViewControllers (#4646)
- Add threshold to always log fatal logs (#4707)

### Improvements

- Add error logging for invalid `cacheDirectoryPath` (#4693)

## 8.43.1-beta.0

### Fixes
Expand All @@ -15,7 +19,6 @@
- Replace occurences of `strncpy` with `strlcpy` (#4636)
- Fix span recording for `NSFileManager.createFileAtPath` starting with iOS 18, macOS 15 and tvOS 18. This feature is experimental and must be enabled by setting the option `experimental.enableFileManagerSwizzling` to `true` (#4634)


### Internal

- Update to Xcode 16.2 in workflows (#4673)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ - (nullable instancetype)initWithOptions:(SentryOptions *)options
dispatchQueueWrapper:dispatchQueue
error:&error];
if (error != nil) {
SENTRY_LOG_ERROR(@"Cannot init filesystem.");
SENTRY_LOG_FATAL(@"Failed to initialize file system: %@", error.localizedDescription);
return nil;
}
return [self initWithOptions:options
Expand Down
61 changes: 44 additions & 17 deletions Sources/Sentry/SentryFileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,44 @@

NSString *const EnvelopesPathComponent = @"envelopes";

BOOL
isErrorPathTooLong(NSError *error)
{
NSError *underlyingError = NULL;
if (@available(macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5, *)) {
underlyingError = error.underlyingErrors.firstObject;
}
if (underlyingError == NULL) {
id errorInUserInfo = [error.userInfo valueForKey:NSUnderlyingErrorKey];
if ([errorInUserInfo isKindOfClass:[NSError class]]) {
underlyingError = errorInUserInfo;
} else {
SENTRY_LOG_FATAL(@"Failed to get underlying error from error: %@", error);
}
}
if (error.domain == NSPOSIXErrorDomain && error.code == ENAMETOOLONG) {
return YES;
}
return NO;
}

BOOL
createDirectoryIfNotExists(NSString *path, NSError **error)
{
if (![[NSFileManager defaultManager] createDirectoryAtPath:path
withIntermediateDirectories:YES
attributes:nil
error:error]) {
*error = NSErrorFromSentryErrorWithUnderlyingError(kSentryErrorFileIO,
[NSString stringWithFormat:@"Failed to create the directory at path %@.", path],
*error);
return NO;
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:path
withIntermediateDirectories:YES
attributes:nil
error:error];
if (success) {
return YES;
}
return YES;

if (isErrorPathTooLong(*error)) {
SENTRY_LOG_FATAL(@"Failed to create directory, path is too long: %@", path);
}
*error = NSErrorFromSentryErrorWithUnderlyingError(kSentryErrorFileIO,
[NSString stringWithFormat:@"Failed to create the directory at path %@.", path], *error);
return NO;
}

/**
Expand All @@ -45,15 +70,14 @@
{
NSError *error = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager removeItemAtPath:path error:&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 {
if ([fileManager removeItemAtPath:path error:&error]) {
SENTRY_LOG_DEBUG(@"Successfully deleted file at %@", path);
} else if (error.code == NSFileNoSuchFileError) {
SENTRY_LOG_DEBUG(@"No file to delete at %@", path);
} else if (isErrorPathTooLong(error)) {
SENTRY_LOG_FATAL(@"Failed to remove file, path is too long: %@", path);
} else {
SENTRY_LOG_ERROR(@"Error occurred while deleting file at %@ because of %@", path, error);
}
}

Expand Down Expand Up @@ -102,9 +126,12 @@ - (nullable instancetype)initWithOptions:(SentryOptions *)options
[self removeFileAtPath:self.eventsPath];

if (!createDirectoryIfNotExists(self.sentryPath, error)) {
SENTRY_LOG_FATAL(@"Failed to create Sentry SDK working directory: %@", self.sentryPath);
return nil;
}
if (!createDirectoryIfNotExists(self.envelopesPath, error)) {
SENTRY_LOG_FATAL(
@"Failed to create Sentry SDK envelopes directory: %@", self.envelopesPath);
return nil;
}

Expand Down

0 comments on commit 39c747b

Please sign in to comment.