Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "feat: send an error to sentry on date parsing issue" #1002

Merged
merged 2 commits into from
Sep 29, 2023
Merged
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
2 changes: 1 addition & 1 deletion .package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Infomaniak/ios-core",
"state" : {
"revision" : "307e6cb8da9ad0cf02aa3502492596c082d5247d"
"revision" : "025c5dffa801d0ffe4e55730897466784f42564f"
}
},
{
Expand Down
33 changes: 2 additions & 31 deletions MailCore/Models/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import Foundation
import InfomaniakCore
import MailResources
import RealmSwift
import Sentry

// TODO: move to core
public extension String {
Expand Down Expand Up @@ -146,11 +145,6 @@ public enum MessageDKIM: String, Codable, PersistableEnum {
}

public final class Message: Object, Decodable, Identifiable {
public enum ErrorDomain: Error {
/// Unable to create a date from the input data
case dateParsingFailed
}

@Persisted(primaryKey: true) public var uid = ""
@Persisted public var messageId: String?
@Persisted public var subject: String?
Expand Down Expand Up @@ -323,28 +317,7 @@ public final class Message: Object, Decodable, Identifiable {
self.date = date
} else {
date = Date()
let dateParsingError = Event(level: .error)

let breadcrumb = SentryDebug.createBreadcrumb(
level: .warning,
category: "Thread algo",
message: "Nil message date decoded",
data: ["uid": uid]
)

SentrySDK.capture(error: ErrorDomain.dateParsingFailed) { scope in
if let date = try? values.decode(String.self, forKey: .date) {
scope.setExtra(value: date, key: "dateString")
}

if let date = try? values.decode(Data.self, forKey: .date) {
scope.setExtra(value: date, key: "dateRaw")
}

scope.addBreadcrumb(breadcrumb)
}

SentrySDK.addBreadcrumb(breadcrumb)
SentryDebug.nilDateParsingBreadcrumb(uid: uid)
}
size = try values.decode(Int.self, forKey: .size)
from = try values.decode(List<Recipient>.self, forKey: .from)
Expand Down Expand Up @@ -373,9 +346,7 @@ public final class Message: Object, Decodable, Identifiable {
if let inReplyTo = try? values.decodeIfPresent(String.self, forKey: .inReplyTo) {
self.inReplyTo = inReplyTo
} else if let inReplyToList = try values.decodeIfPresent([String].self, forKey: .inReplyTo) {
SentrySDK.capture(message: "Found an array of inReplyTo") { scope in
scope.setContext(value: ["ids": inReplyToList.joined(separator: ", ")], key: "inReplyToList")
}
SentryDebug.messageHasInReplyTo(inReplyToList)
inReplyTo = inReplyToList.first
}

Expand Down
44 changes: 33 additions & 11 deletions MailCore/Utils/SentryDebug.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import RealmSwift
import Sentry

public enum SentryDebug {
// MARK: - Errors

public static let knownDebugDate = Date(timeIntervalSince1970: 1_893_456_000)
static func sendMissingMessagesSentry(sentUids: [String], receivedMessages: [Message], folder: Folder, newCursor: String?) {
if receivedMessages.count != sentUids.count {
Expand Down Expand Up @@ -85,17 +87,6 @@ public enum SentryDebug {
}
}

static func createBreadcrumb(level: SentryLevel,
category: String,
message: String,
data: [String: Any]? = nil) -> Breadcrumb {
let crumb = Breadcrumb(level: level, category: category)
crumb.type = level == .info ? "info" : "error"
crumb.message = message
crumb.data = data
return crumb
}

static func captureWrongDate(step: String, startDate: Date, folder: Folder, alreadyWrongIds: [String], realm: Realm) -> Bool {
guard let freshFolder = folder.fresh(using: realm) else { return false }

Expand Down Expand Up @@ -134,4 +125,35 @@ public enum SentryDebug {
)
}
}

static func messageHasInReplyTo(_ inReplyToList: [String]) {
SentrySDK.capture(message: "Found an array of inReplyTo") { scope in
scope.setContext(value: ["ids": inReplyToList.joined(separator: ", ")], key: "inReplyToList")
}
}

// MARK: - Breadcrumb

enum Category {
static let ThreadAlgorithm = "Thread algo"
}

private static func createBreadcrumb(level: SentryLevel,
category: String,
message: String,
data: [String: Any]? = nil) -> Breadcrumb {
let crumb = Breadcrumb(level: level, category: category)
crumb.type = level == .info ? "info" : "error"
crumb.message = message
crumb.data = data
return crumb
}

static func nilDateParsingBreadcrumb(uid: String) {
let breadcrumb = createBreadcrumb(level: .warning,
category: Category.ThreadAlgorithm,
message: "Nil message date decoded",
data: ["uid": uid])
SentrySDK.addBreadcrumb(breadcrumb)
}
}
Loading