import Foundation import ParcelConfig import ParcelCore import ParcelEngine import ParcelUI struct AppFailure: Error, LocalizedError { let message: String var errorDescription: String? { message } } enum AppText { static func string(_ key: String) -> String { Bundle.module.localizedString(forKey: key, value: nil, table: "App") } static func localized(_ value: String.LocalizationValue) -> String { String(localized: value, table: "App", bundle: .module) } static func notice(_ key: String) -> String { Bundle.module.localizedString(forKey: key, value: nil, table: "Notices") } static func configurationNotice(_ diagnostics: [ConfigDiagnostic]) -> String? { diagnostics.first(where: { $0.severity == .error })?.description } static func humanFailure(_ error: any Error) -> String? { if let error = error as? AppFailure { return error.message } if let error = error as? EngineError { switch error { case .invalidConfiguration: return AppNotices.Kind.configuration.message case .stopped, .startInProgress, .settingsUnavailable: return error.errorDescription } } if let error = error as? EngineFrameAcceptanceError { return error.errorDescription } if let error = error as? EngineCommandSuspensionError { return error.errorDescription } if let error = error as? EngineWindowCommandError { return error.errorDescription } if error is AppTabViewLayout.Failure || error is TabViewSelection.ValidationError { return string("Tab View could not open. Try again after windows settle.") } if let error = error as? MinimizedWindowRestoreError { switch error { case .staleWindow: return string("That window is no longer available.") case .busy: return string("That window is already being restored.") case .unconfirmed: return string("The window did not restore. Try again.") } } if let error = error as? HoverActionError { return error.errorDescription } if let error = error as? AppWorkspaceMemoryFailure { return error.errorDescription } return nil } static func failure(_ key: String) -> AppFailure { AppFailure(message: string(key)) } static func detail(_ key: String, _ detail: String) -> AppFailure { AppFailure(message: String(format: string(key), locale: .current, detail)) } }