mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 16:24:11 +00:00
Fix libdispatch main-thread trap when logging Sentry crash events
Sentry's beforeSend runs on a background queue, but Event.crashLog read UIDevice.current there, which carries a main-thread dispatch assertion and trapped libdispatch. Read the device values on the main thread at setup and pass them into the now-nonisolated crashLog.
This commit is contained in:
@@ -1020,8 +1020,11 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mirror every crash into our own logs (which ship with rageshakes) before it's sent to Sentry.
|
// Mirror every crash into our own logs (which ship with rageshakes) before it's sent to Sentry.
|
||||||
options.beforeSend = { event in
|
// Device values are read here on the main thread; beforeSend runs on a background queue.
|
||||||
if let crashLog = event.crashLog {
|
let deviceModel = UIDevice.current.model
|
||||||
|
let systemVersion = UIDevice.current.systemVersion
|
||||||
|
options.beforeSend = { @Sendable event in
|
||||||
|
if let crashLog = event.crashLog(deviceModel: deviceModel, systemVersion: systemVersion) {
|
||||||
MXLog.error("Sentry crash event \(event.eventId.sentryIdString):\n\(crashLog)")
|
MXLog.error("Sentry crash event \(event.eventId.sentryIdString):\n\(crashLog)")
|
||||||
}
|
}
|
||||||
return event
|
return event
|
||||||
|
|||||||
@@ -8,12 +8,14 @@
|
|||||||
|
|
||||||
import MatrixRustSDK
|
import MatrixRustSDK
|
||||||
import Sentry
|
import Sentry
|
||||||
import UIKit
|
|
||||||
|
|
||||||
extension Event {
|
extension Event {
|
||||||
/// A human readable crash log matching the format used by the legacy app.
|
/// A human readable crash log matching the format used by the legacy app.
|
||||||
/// `nil` for non-crash events (handled errors, transactions, etc.).
|
/// `nil` for non-crash events (handled errors, transactions, etc.).
|
||||||
var crashLog: String? {
|
///
|
||||||
|
/// Device values must be read on the main thread and passed in. `beforeSend`
|
||||||
|
/// runs on a background queue and touching `UIDevice.current` there traps libdispatch.
|
||||||
|
nonisolated func crashLog(deviceModel: String, systemVersion: String) -> String? {
|
||||||
guard let exceptions,
|
guard let exceptions,
|
||||||
exceptions.contains(where: { $0.mechanism?.handled?.boolValue == false }) else {
|
exceptions.contains(where: { $0.mechanism?.handled?.boolValue == false }) else {
|
||||||
return nil
|
return nil
|
||||||
@@ -21,14 +23,13 @@ extension Event {
|
|||||||
|
|
||||||
let reason = exceptions.map { "\($0.type ?? "Unknown"): \($0.value ?? "")" }.joined(separator: "\n")
|
let reason = exceptions.map { "\($0.type ?? "Unknown"): \($0.value ?? "")" }.joined(separator: "\n")
|
||||||
let infoPlist = InfoPlistReader.main
|
let infoPlist = InfoPlistReader.main
|
||||||
let device = UIDevice.current
|
|
||||||
|
|
||||||
return """
|
return """
|
||||||
\(reason)
|
\(reason)
|
||||||
Application: \(infoPlist.bundleExecutable) (\(infoPlist.bundleIdentifier))
|
Application: \(infoPlist.bundleExecutable) (\(infoPlist.bundleIdentifier))
|
||||||
Application version: \(infoPlist.bundleShortVersionString) (\(infoPlist.bundleVersion))
|
Application version: \(infoPlist.bundleShortVersionString) (\(infoPlist.bundleVersion))
|
||||||
Matrix SDK version: \(sdkGitSha())
|
Matrix SDK version: \(sdkGitSha())
|
||||||
\(device.model) \(device.systemVersion)
|
\(deviceModel) \(systemVersion)
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user