Skip to content

Commit

Permalink
Merge pull request #961 from Infomaniak/sentryOnParsingDateError
Browse files Browse the repository at this point in the history
feat: send an error to sentry on date parsing issue
  • Loading branch information
Ambrdctr committed Sep 4, 2023
2 parents 847777e + 1326f53 commit 76e32ea
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions MailCore/Models/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ 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 @@ -318,13 +323,28 @@ public final class Message: Object, Decodable, Identifiable {
self.date = date
} else {
date = Date()
SentrySDK
.addBreadcrumb(SentryDebug.createBreadcrumb(
level: .warning,
category: "Thread algo",
message: "Nil message date decoded",
data: ["uid": uid]
))
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)
}
size = try values.decode(Int.self, forKey: .size)
from = try values.decode(List<Recipient>.self, forKey: .from)
Expand Down

0 comments on commit 76e32ea

Please sign in to comment.