Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Sources/Raygun/RaygunClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,42 @@ - (void)sendMessage:(RaygunMessage *)message {
}
}

- (BOOL)storeCrashReport:(RaygunMessage *)message {
if (message == nil) {
[RaygunLogger logWarning:@"Failed to store crash report - Message object cannot be nil"];
return NO;
}

// Call groupingKeyProvider if it's set
if (self.groupingKeyProvider != nil && message.details != nil) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: sendMessage also checks message != nil in this condition. Not a bug, just noting the divergence.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also possibly worthwhile making the same as in sendMessage.

NSString *groupingKey = self.groupingKeyProvider(message.details);

if (groupingKey != nil && ![groupingKey isEqualToString:@""]) {
message.details.groupingKey = groupingKey;
[RaygunLogger logDebug:@"Applied custom grouping key from provider: %@", groupingKey];
}
}

BOOL send = YES;
if (_beforeSendMessage != nil) {
send = _beforeSendMessage(message);
}

if (!send) {
[RaygunLogger logDebug:@"Crash report was discarded by beforeSendMessage"];
return NO;
}

NSString *path = [_fileManager storeCrashReport:message withMaxReportsStored:self.maxReportsStoredOnDevice];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses direct access to _fileManager whereas the existing sendMessage method (L328, L346) uses self.fileManager property accessor.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably worthwhile aligning.

if (path) {
[RaygunLogger logDebug:@"Stored crash report to %@", path];
return YES;
}

[RaygunLogger logError:@"Failed to store crash report to disk"];
return NO;
}

- (NSError *)getInnerError:(NSError *)error {
NSError *innerErrror = error.userInfo[NSUnderlyingErrorKey];
if (innerErrror) {
Expand Down
13 changes: 13 additions & 0 deletions Sources/public/RaygunClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,19 @@ NS_SWIFT_NAME(send(error:tags:customData:));
- (void)sendMessage:(RaygunMessage *)message
NS_SWIFT_NAME(send(message:));

/*
* Synchronously store a crash report to disk.
* The report will be sent to Raygun on the next app launch when enableCrashReporting is called.
* This is intended for use in contexts where the process is about to terminate (e.g. unhandled exception hooks)
* and asynchronous network requests would not complete.
*
* @param message The crash report to be stored
*
* @return YES if the report was successfully stored, NO otherwise.
*/
- (BOOL)storeCrashReport:(RaygunMessage *)message
NS_SWIFT_NAME(store(crashReport:));

/*
* Manually record a breadcrumb that will be included in the next crash report.
*
Expand Down