-
Notifications
You must be signed in to change notification settings - Fork 19
/
InstallationTicketMachineError+LocalizedError.swift
48 lines (42 loc) · 1.33 KB
/
InstallationTicketMachineError+LocalizedError.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// InstallationTicketMachineError+LocalizedError.swift
// Tophat
//
// Created by Lukas Romsicki on 2024-10-04.
// Copyright © 2024 Shopify. All rights reserved.
//
import Foundation
import TophatFoundation
extension InstallationTicketMachineError: LocalizedError {
var errorDescription: String? {
switch self {
case .noCompatibleDevices(let providedBuildTypes):
"No \(description(for: providedBuildTypes)) Selected"
case .noSelectedDevices:
"No Device Selected"
}
}
var failureReason: String? {
switch self {
case .noCompatibleDevices:
"None of the specified builds are compatible with the selected devices."
default:
nil
}
}
var recoverySuggestion: String? {
switch self {
case .noCompatibleDevices(let providedBuildTypes):
let text = description(for: providedBuildTypes)
return "Select \(text.indefiniteArticle) \(text) using the Tophat menu and try again."
case .noSelectedDevices:
return "Select a device from the Tophat menu and try again."
}
}
private func description(for providedBuildTypes: [Platform: Set<DeviceType>]) -> String {
providedBuildTypes.map { "\($0.key) \(description(for: $0.value))" }.formatted(.list(type: .or))
}
private func description(for targets: Set<DeviceType>) -> String {
targets.map { String(describing: $0) }.formatted(.list(type: .or))
}
}