Zum Inhalt

apple/PhysarumApp/Sources/UI/ErrorPresenter.swift

import Foundation

/// Central sink for user-facing errors. Subsystems and views call `report`;
/// a single `.errorAlert` mounted at each app root presents `current`.
@Observable
final class ErrorPresenter {
    var current: UserFacingError?

    /// Present an error. Must be called on the main thread (the only thread
    /// SwiftUI reads `current` from). The five report sites already hop to main.
    func report(_ error: UserFacingError) {
        dispatchPrecondition(condition: .onQueue(.main))
        current = error
    }

    func report(title: String, message: String, recovery: RecoveryAction = .none) {
        report(UserFacingError(title: title, message: message, recovery: recovery))
    }

    func dismiss() { current = nil }
}