Skip to content

Commit

Permalink
Merge pull request #6611 from vector-im/andy/sentry
Browse files Browse the repository at this point in the history
Track all errors in Sentry
  • Loading branch information
Anderas committed Aug 24, 2022
2 parents de291a5 + 48ce9c8 commit 966069e
Show file tree
Hide file tree
Showing 45 changed files with 129 additions and 74 deletions.
2 changes: 1 addition & 1 deletion Riot/Categories/UIViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ extension UIViewController {
// Even when .never, needs to be true otherwise animation will be broken on iOS11, 12, 13
navigationController?.navigationBar.prefersLargeTitles = true
@unknown default:
MXLog.failure("[UIViewController] setLargeTitleDisplayMode: Missing handler for \(largeTitleDisplayMode)")
MXLog.failure("[UIViewController] setLargeTitleDisplayMode: Missing handler", context: largeTitleDisplayMode)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Riot/Managers/Logging/MatrixSDKLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MatrixSDKLogger: LoggerProtocol {
static func warning(_ message: @autoclosure () -> Any, _ file: String = #file, _ function: String = #function, line: Int = #line, context: Any? = nil) {
MXLog.warning(message(), file, function, line: line, context: context)
}
static func error(_ message: @autoclosure () -> Any, _ file: String = #file, _ function: String = #function, line: Int = #line, context: Any? = nil) {
static func error(_ message: @autoclosure () -> StaticString, _ file: String = #file, _ function: String = #function, line: Int = #line, context: Any? = nil) {
MXLog.error(message(), file, function, line: line, context: context)
}
}
10 changes: 5 additions & 5 deletions Riot/Managers/URLPreviews/Core Data/URLPreviewStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ class URLPreviewStore {
// Load the persistent stores into the container
container.loadPersistentStores { storeDescription, error in
if let error = error {
MXLog.error("[URLPreviewStore] Core Data container error: \(error.localizedDescription)")
MXLog.error("[URLPreviewStore] Core Data container", context: error)
}

if let url = storeDescription.url {
do {
try FileManager.default.excludeItemFromBackup(at: url)
} catch {
MXLog.error("[URLPreviewStore] Cannot exclude Core Data from backup: \(error.localizedDescription)")
MXLog.error("[URLPreviewStore] Cannot exclude Core Data from backup", context: error)
}
}
}
Expand Down Expand Up @@ -130,7 +130,7 @@ class URLPreviewStore {
do {
try context.execute(NSBatchDeleteRequest(fetchRequest: request))
} catch {
MXLog.error("[URLPreviewStore] Error executing batch delete request: \(error.localizedDescription)")
MXLog.error("[URLPreviewStore] Error executing batch delete request", context: error)
}
}

Expand All @@ -140,7 +140,7 @@ class URLPreviewStore {
_ = try context.execute(NSBatchDeleteRequest(fetchRequest: URLPreviewDataMO.fetchRequest()))
_ = try context.execute(NSBatchDeleteRequest(fetchRequest: URLPreviewUserDataMO.fetchRequest()))
} catch {
MXLog.error("[URLPreviewStore] Error executing batch delete request: \(error.localizedDescription)")
MXLog.error("[URLPreviewStore] Error executing batch delete request", context: error)
}
}

Expand Down Expand Up @@ -171,7 +171,7 @@ class URLPreviewStore {
do {
try context.save()
} catch {
MXLog.error("[URLPreviewStore] Error saving changes: \(error.localizedDescription)")
MXLog.error("[URLPreviewStore] Error saving changes", context: error)
}
}
}
2 changes: 1 addition & 1 deletion Riot/Modules/Analytics/Analytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ extension Analytics: MXAnalyticsDelegate {
capture(event: event)
}

func trackNonFatalIssue(_ issue: String, details: [String : Any]?) {
func trackNonFatalIssue(_ issue: String, details: [String: Any]?) {
monitoringClient.trackNonFatalIssue(issue, details: details)
}
}
4 changes: 3 additions & 1 deletion Riot/Modules/Analytics/SentryMonitoringClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ struct SentryMonitoringClient {
MXLog.debug("[SentryMonitoringClient] Started")
SentrySDK.start { options in
options.dsn = Self.sentryDSN
options.tracesSampleRate = 1.0

// Collecting only 10% of all events
options.tracesSampleRate = 0.1

options.beforeSend = { event in
MXLog.debug("[SentryMonitoringClient] Issue detected: \(event)")
Expand Down
4 changes: 3 additions & 1 deletion Riot/Modules/Application/LegacyAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,9 @@ - (BOOL)handleUniversalLinkWithParameters:(UniversalLinkParameters*)universalLin
event = eventFromServer;
dispatch_group_leave(eventDispatchGroup);
} failure:^(NSError *error) {
MXLogError(@"[LegacyAppDelegate] handleUniversalLinkWithParameters: event fetch failed: %@", error);
MXLogErrorDetails(@"[LegacyAppDelegate] handleUniversalLinkWithParameters: event fetch failed", @{
@"error": error ?: @"unknown"
});
dispatch_group_leave(eventDispatchGroup);
}];
}
Expand Down
4 changes: 2 additions & 2 deletions Riot/Modules/Authentication/SessionVerificationListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class SessionVerificationListener {
MXLog.debug("[SessionVerificationListener] sessionStateDidChange: Bootstrap succeeded")
self.completion?(.authenticationIsComplete)
} failure: { error in
MXLog.error("[SessionVerificationListener] sessionStateDidChange: Bootstrap failed. Error: \(error)")
MXLog.error("[SessionVerificationListener] sessionStateDidChange: Bootstrap failed", context: error)
crypto.setOutgoingKeyRequestsEnabled(true, onComplete: nil)
self.completion?(.authenticationIsComplete)
}
Expand Down Expand Up @@ -128,7 +128,7 @@ class SessionVerificationListener {
self.completion?(.authenticationIsComplete)
}
} failure: { [weak self] error in
MXLog.error("[SessionVerificationListener] sessionStateDidChange: Fail to refresh crypto state with error: \(error)")
MXLog.error("[SessionVerificationListener] sessionStateDidChange: Fail to refresh crypto state", context: error)
crypto.setOutgoingKeyRequestsEnabled(true, onComplete: nil)
self?.completion?(.authenticationIsComplete)
}
Expand Down
6 changes: 5 additions & 1 deletion Riot/Modules/Common/Recents/RecentsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2046,7 +2046,11 @@ - (void)scrollToTheTopTheNextRoomWithMissedNotificationsInSection:(NSInteger)sec
}
else if (section >= self.recentsTableView.numberOfSections)
{
MXLogFailure(@"[RecentsViewController] Section %ld is invalid in a table view with only %ld sections", section, self.recentsTableView.numberOfSections);
NSDictionary *details = @{
@"section": @(section),
@"number_of_sections": @(self.recentsTableView.numberOfSections)
};
MXLogFailureDetails(@"[RecentsViewController] Section in a table view is invalid", details);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ final class KeyVerificationVerifyByScanningViewController: UIViewController {
do {
return try codeGenerator.generateCode(from: data, with: codeImageView.frame.size)
} catch {
MXLog.error("[KeyVerificationVerifyByScanningViewController] qrCodeImage: cannot generate QR code - \(error)")
MXLog.error("[KeyVerificationVerifyByScanningViewController] qrCodeImage: cannot generate QR code", context: error)
return nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/LocationSharing/LocationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,6 @@ extension LocationManager: CLLocationManagerDelegate {
}

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
MXLog.error("[LocationManager] Did failed with error :\(error)")
MXLog.error("[LocationManager] Did failed", context: error)
}
}
2 changes: 1 addition & 1 deletion Riot/Modules/LocationSharing/UserLocationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class UserLocationService: UserLocationServiceProtocol {
case .success:
break
case .failure(let error):
MXLog.error("Fail to send location with error \(error)")
MXLog.error("Fail to send location", context: error)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1542,12 +1542,16 @@ - (void)attemptDeviceRehydrationWithKeyData:(NSData *)keyData

if (retry)
{
MXLogError(@"[MXKAuthenticationViewController] attemptDeviceRehydration: device rehydration failed due to error: %@. Retrying", error);
MXLogErrorDetails(@"[MXKAuthenticationViewController] attemptDeviceRehydration: device rehydration failed due to error: Retrying", @{
@"error": error ?: @"unknown"
});
[self attemptDeviceRehydrationWithKeyData:keyData credentials:credentials retry:NO];
return;
}

MXLogError(@"[MXKAuthenticationViewController] attemptDeviceRehydration: device rehydration failed due to error: %@", error);
MXLogErrorDetails(@"[MXKAuthenticationViewController] attemptDeviceRehydration: device rehydration failed due to error", @{
@"error": error ?: @"unknown"
});

[self _createAccountWithCredentials:credentials];
}];
Expand Down
12 changes: 9 additions & 3 deletions Riot/Modules/MatrixKit/Models/Account/MXKAccount.m
Original file line number Diff line number Diff line change
Expand Up @@ -1618,11 +1618,15 @@ - (void)attemptDeviceDehydrationWithKeyData:(NSData *)keyData
if (retry)
{
[self attemptDeviceDehydrationWithKeyData:keyData retry:NO success:success failure:failure];
MXLogError(@"[MXKAccount] attemptDeviceDehydrationWithRetry: device dehydration failed due to error: %@. Retrying.", error);
MXLogErrorDetails(@"[MXKAccount] attemptDeviceDehydrationWithRetry: device dehydration failed due to error: Retrying.", @{
@"error": error ?: @"unknown"
});
}
else
{
MXLogError(@"[MXKAccount] attemptDeviceDehydrationWithRetry: device dehydration failed due to error: %@", error);
MXLogErrorDetails(@"[MXKAccount] attemptDeviceDehydrationWithRetry: device dehydration failed due to error", @{
@"error": error ?: @"unknown"
});

if (failure)
{
Expand Down Expand Up @@ -1772,7 +1776,9 @@ - (void)onDateTimeFormatUpdate

dispatch_group_leave(dispatchGroup);
} failure:^(NSError *error) {
MXLogError(@"[MXKAccount] onDateTimeFormatUpdate: event fetch failed: %@", error);
MXLogErrorDetails(@"[MXKAccount] onDateTimeFormatUpdate: event fetch failed", @{
@"error": error ?: @"unknown"
});
dispatch_group_leave(dispatchGroup);
}];
}
Expand Down
4 changes: 3 additions & 1 deletion Riot/Modules/MatrixKit/Models/Room/MXKAttachment.m
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,9 @@ + (void)clearCache
NSError *error;
BOOL result = [NSFileManager.defaultManager removeItemAtPath:[temporaryDirectoryPath stringByAppendingPathComponent:filePath] error:&error];
if (!result && error) {
MXLogError(@"[MXKAttachment] Failed deleting temporary file with error: %@", error);
MXLogErrorDetails(@"[MXKAttachment] Failed deleting temporary file with error", @{
@"error": error ?: @"unknown"
});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extension MarkdownToHTMLRenderer: MarkdownToHTMLRendererProtocol {
ast.repairLinks()
return try DownHTMLRenderer.astToHTML(ast, options: options)
} catch {
MXLog.error("[MarkdownToHTMLRenderer] renderToHTML failed with string: \(markdown)")
MXLog.error("[MarkdownToHTMLRenderer] renderToHTML failed")
return nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class MXKVideoThumbnailGenerator: NSObject {
let image = try assetImageGenerator.copyCGImage(at: .zero, actualTime: nil)
thumbnailImage = UIImage(cgImage: image)
} catch {
MXLog.error(error.localizedDescription)
MXLog.error("[MXKVideoThumbnailGenerator] generateThumbnail:", context: error)
thumbnailImage = nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,8 @@ - (void)paste:(id)sender
pasteboardImage = [UIImage imageWithData:[dict objectForKey:key]];
}
else {
MXLogError(@"[MXKRoomInputToolbarView] Unsupported image format %@ for mimetype %@ pasted.", MIMEType, NSStringFromClass([[dict objectForKey:key] class]));
NSString *message = [NSString stringWithFormat:@"[MXKRoomInputToolbarView] Unsupported image format %@ for mimetype %@ pasted.", MIMEType, NSStringFromClass([[dict objectForKey:key] class])];
MXLogError(message);
}

if (pasteboardImage)
Expand Down
8 changes: 6 additions & 2 deletions Riot/Modules/Room/CellData/RoomBubbleCellData.m
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,9 @@ - (void)updateBeaconInfoSummaryWithId:(NSString *)eventId andEvent:(MXEvent*)eve
{
if (event.eventType != MXEventTypeBeaconInfo)
{
MXLogError(@"[RoomBubbleCellData] Try to update beacon info summary with wrong event type with event id %@", eventId);
MXLogErrorDetails(@"[RoomBubbleCellData] Try to update beacon info summary with wrong event type", @{
@"event_id": eventId ?: @"unknown"
});
return;
}

Expand All @@ -1378,7 +1380,9 @@ - (void)updateBeaconInfoSummaryWithId:(NSString *)eventId andEvent:(MXEvent*)eve
// A start beacon info event (isLive == true) should have an associated BeaconInfoSummary
if (beaconInfo && beaconInfo.isLive)
{
MXLogError(@"[RoomBubbleCellData] No beacon info summary found for beacon info start event with id %@", eventId);
MXLogErrorDetails(@"[RoomBubbleCellData] No beacon info summary found for beacon info start event", @{
@"event_id": eventId ?: @"unknown"
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ extension ContactsPickerViewModel: ContactsTableViewControllerDelegate {
case .success:
self.coordinatorDelegate?.contactsPickerViewModelDidEndInvite(self)
case .failure:
MXLog.error("[ContactsPickerViewModel] Failed to invite \(participantId) due to error; \(response.error ?? "nil")")
MXLog.error("[ContactsPickerViewModel] Failed to invite participant", context: response.error)
self.coordinatorDelegate?.contactsPickerViewModel(self, inviteFailedWithError: response.error)
}
}
Expand Down Expand Up @@ -255,7 +255,7 @@ extension ContactsPickerViewModel: ContactsTableViewControllerDelegate {
case .success:
self.coordinatorDelegate?.contactsPickerViewModelDidEndInvite(self)
case .failure:
MXLog.error("[ContactsPickerViewModel] Failed to invite \(participantId) by email due to error; \(response.error ?? "nil")")
MXLog.error("[ContactsPickerViewModel] Failed to invite participant by email", context: response.error)

if let error = response.error as NSError?, error.domain == kMXRestClientErrorDomain, error.code == MXRestClientErrorMissingIdentityServer {
self.coordinatorDelegate?.contactsPickerViewModel(self, inviteFailedWithError: nil)
Expand All @@ -273,7 +273,7 @@ extension ContactsPickerViewModel: ContactsTableViewControllerDelegate {
case .success:
self.coordinatorDelegate?.contactsPickerViewModelDidEndInvite(self)
case .failure:
MXLog.error("[ContactsPickerViewModel] Failed to invite \(participantId) due to error; \(response.error ?? "nil")")
MXLog.error("[ContactsPickerViewModel] Failed to invite participant", context: response.error)
self.coordinatorDelegate?.contactsPickerViewModel(self, inviteFailedWithError: response.error)
}
}
Expand Down
4 changes: 3 additions & 1 deletion Riot/Modules/Room/RoomCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,9 @@ extension RoomCoordinator: RoomViewControllerDelegate {

func threadsCoordinator(for roomViewController: RoomViewController, threadId: String?) -> ThreadsCoordinatorBridgePresenter? {
guard let session = mxSession, let roomId = roomId else {
MXLog.error("[RoomCoordinator] Cannot create threads coordinator for room \(roomId ?? "")")
MXLog.error("[RoomCoordinator] Cannot create threads coordinator for room", context: [
"room_id": roomId
])
return nil
}

Expand Down
8 changes: 6 additions & 2 deletions Riot/Modules/Room/RoomViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ extension RoomViewController {
case .success:
break
case .failure:
MXLog.error("[RoomViewController] sendAttributedTextMessage failed while updating event: \(eventModified.eventId ?? "N/A")")
MXLog.error("[RoomViewController] sendAttributedTextMessage failed while updating event", context: [
"event_id": eventModified.eventId
])
}
}
} else if self.inputToolbar?.sendMode == .edit, let eventModified = eventModified {
Expand All @@ -78,7 +80,9 @@ extension RoomViewController {
//
},
failure: { _ in
MXLog.error("[RoomViewController] sendAttributedTextMessage failed while updating event: \(eventModified.eventId ?? "N/A")")
MXLog.error("[RoomViewController] sendAttributedTextMessage failed while updating event", context: [
"event_id": eventModified.eventId
])
})
} else {
roomDataSource.sendAttributedTextMessage(attributedTextMsg) { response in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ class RoomTimelineLocationView: UIView, NibLoadable, Themable, MGLMapViewDelegat

func mapViewDidFailLoadingMap(_ mapView: MGLMapView, withError error: Error) {

MXLog.error("[RoomTimelineLocationView] Failed to load map with error: \(error)")
MXLog.error("[RoomTimelineLocationView] Failed to load map", context: error)

self.isMapViewLoadingFailed = true
}
Expand Down
Loading

0 comments on commit 966069e

Please sign in to comment.