Files
element-x-ios/ElementX/Sources/Other/Extensions/SentryEvent.swift
T
Stefan Ceriu 10017714e5 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.
2026-06-22 14:45:50 +03:00

36 lines
1.3 KiB
Swift

//
// Copyright 2025 Element Creations Ltd.
// Copyright 2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import MatrixRustSDK
import Sentry
extension Event {
/// A human readable crash log matching the format used by the legacy app.
/// `nil` for non-crash events (handled errors, transactions, etc.).
///
/// 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,
exceptions.contains(where: { $0.mechanism?.handled?.boolValue == false }) else {
return nil
}
let reason = exceptions.map { "\($0.type ?? "Unknown"): \($0.value ?? "")" }.joined(separator: "\n")
let infoPlist = InfoPlistReader.main
return """
\(reason)
Application: \(infoPlist.bundleExecutable) (\(infoPlist.bundleIdentifier))
Application version: \(infoPlist.bundleShortVersionString) (\(infoPlist.bundleVersion))
Matrix SDK version: \(sdkGitSha())
\(deviceModel) \(systemVersion)
"""
}
}