forked from Carthage/Carthage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Errors.swift
411 lines (301 loc) · 13.9 KB
/
Errors.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
import Foundation
import ReactiveSwift
import ReactiveTask
import Tentacle
import XCDBLD
/// Possible errors that can originate from Carthage.
public enum CarthageError: Error {
public typealias VersionRequirement = (specifier: VersionSpecifier, fromDependency: Dependency?)
public struct DuplicatesInArchive: Equatable {
let dictionary: [URL: [URL]]
}
public struct XCFrameworkRequired: Equatable {
let productName: String
let commonArchitectures: Set<String>
let underlyingError: TaskError
}
/// One or more arguments was invalid.
case invalidArgument(description: String)
/// `xcodebuild` did not return a build setting that we needed.
case missingBuildSetting(String)
/// Incompatible version specifiers were given for a dependency.
case incompatibleRequirements(Dependency, VersionRequirement, VersionRequirement)
/// No tagged versions could be found for the dependency.
case taggedVersionNotFound(Dependency)
/// No existent version could be found to satisfy the version specifier for
/// a dependency.
case requiredVersionNotFound(Dependency, VersionSpecifier)
/// No valid versions could be found, given the list of dependencies to update
case unsatisfiableDependencyList([String])
/// No entry could be found in Cartfile for a dependency with this name.
case unknownDependencies([String])
/// No entry could be found in Cartfile.resolved for a dependency with this name.
case unresolvedDependencies([String])
/// Failed to check out a repository.
case repositoryCheckoutFailed(workingDirectoryURL: URL, reason: String, underlyingError: NSError?)
/// Failed to read a file or directory at the given URL.
case readFailed(URL, NSError?)
/// Failed to write a file or directory at the given URL.
case writeFailed(URL, NSError?)
/// No available simulators could be found
case noAvailableSimulators(platformName: String)
/// An error occurred parsing a Carthage file or task result
case parseError(description: String)
/// An error occurred parsing the binary-only framework definition file
case invalidBinaryJSON(URL, BinaryJSONError)
/// An expected environment variable wasn't found.
case missingEnvironmentVariable(variable: String)
/// An error occurred reading a framework's architectures.
case invalidArchitectures(description: String)
/// An error occurred reading a dSYM or framework's UUIDs.
case invalidUUIDs(description: String)
/// The project is not sharing any framework schemes, so Carthage cannot
/// discover them.
case noSharedFrameworkSchemes(Dependency, Set<SDK>)
/// The project is not sharing any schemes, so Carthage cannot discover
/// them.
case noSharedSchemes(ProjectLocator, (Server, Repository)?)
/// Timeout whilst running `xcodebuild`
case xcodebuildTimeout(ProjectLocator)
/// A cartfile contains duplicate dependencies, either in itself or across
/// other cartfiles.
case duplicateDependencies([DuplicateDependency])
/// There was a cycle between dependencies in the associated graph.
case dependencyCycle([Dependency: Set<Dependency>])
/// A request to the GitHub API failed.
case gitHubAPIRequestFailed(Client.Error)
case gitHubAPITimeout
case buildFailed(TaskError, log: URL?)
case unknownFrameworkSwiftVersion(String)
/// An error occurred while shelling out.
case taskError(TaskError)
/// An internal error occurred
case internalError(description: String)
/// Cartfile.resolved contains incompatible versions
case invalidResolvedCartfile([CompatibilityInfo])
/// An archive (.zip, .gz, .bz2 ...) contains binaries that would
/// be copied to the same destination path
case duplicatesInArchive(duplicates: DuplicatesInArchive)
/// (cause)
///
/// Building universal frameworks with common architectures is not possible.
/// The device and simulator slices for "(productName)" both build for: (commonArchitectures)
/// Rebuild with --use-xcframeworks to create an xcframework bundle instead.
case xcframeworkRequired(XCFrameworkRequired)
}
extension CarthageError {
public init(scannableError: ScannableError) {
self = .parseError(description: "\(scannableError)")
}
}
private func == (_ lhs: CarthageError.VersionRequirement, _ rhs: CarthageError.VersionRequirement) -> Bool {
return lhs.specifier == rhs.specifier && lhs.fromDependency == rhs.fromDependency
}
extension CarthageError: Equatable {
public static func == (_ lhs: CarthageError, _ rhs: CarthageError) -> Bool { // swiftlint:disable:this cyclomatic_complexity function_body_length
switch (lhs, rhs) {
case let (.invalidArgument(left), .invalidArgument(right)):
return left == right
case let (.missingBuildSetting(left), .missingBuildSetting(right)):
return left == right
case let (.incompatibleRequirements(left, la, lb), .incompatibleRequirements(right, ra, rb)):
let specifiersEqual = (la == ra && lb == rb) || (la == rb && rb == la)
return left == right && specifiersEqual
case let (.taggedVersionNotFound(left), .taggedVersionNotFound(right)):
return left == right
case let (.requiredVersionNotFound(left, leftVersion), .requiredVersionNotFound(right, rightVersion)):
return left == right && leftVersion == rightVersion
case let (.unsatisfiableDependencyList(left), .unsatisfiableDependencyList(right)):
return left == right
case let (.repositoryCheckoutFailed(la, lb, lc), .repositoryCheckoutFailed(ra, rb, rc)):
return la == ra && lb == rb && lc == rc
case let (.readFailed(la, lb), .readFailed(ra, rb)):
return la == ra && lb == rb
case let (.writeFailed(la, lb), .writeFailed(ra, rb)):
return la == ra && lb == rb
case let (.parseError(left), .parseError(right)):
return left == right
case let (.invalidBinaryJSON(leftUrl, leftError), .invalidBinaryJSON(rightUrl, rightError)):
return leftUrl == rightUrl && leftError == rightError
case let (.missingEnvironmentVariable(left), .missingEnvironmentVariable(right)):
return left == right
case let (.invalidArchitectures(left), .invalidArchitectures(right)):
return left == right
case let (.noSharedFrameworkSchemes(la, lb), .noSharedFrameworkSchemes(ra, rb)):
return la == ra && lb == rb
case let (.noSharedSchemes(la, lb), .noSharedSchemes(ra, rb)):
guard la == ra else { return false }
switch (lb, rb) {
case (nil, nil):
return true
case let ((lb1, lb2)?, (rb1, rb2)?):
return lb1 == rb1 && lb2 == rb2
default:
return false
}
case let (.duplicateDependencies(left), .duplicateDependencies(right)):
return left.sorted() == right.sorted()
case let (.gitHubAPIRequestFailed(left), .gitHubAPIRequestFailed(right)):
return left == right
case (.gitHubAPITimeout, .gitHubAPITimeout):
return true
case let (.buildFailed(la, lb), .buildFailed(ra, rb)):
return la == ra && lb == rb
case let (.taskError(left), .taskError(right)):
return left == right
case let (.internalError(left), .internalError(right)):
return left == right
case let (.duplicatesInArchive(left), .duplicatesInArchive(right)):
return left == right
case let (.xcframeworkRequired(left), .xcframeworkRequired(right)):
return left == right
default:
return false
}
}
}
extension CarthageError: CustomStringConvertible {
public var description: String {
switch self {
case let .invalidArgument(description):
return description
case let .missingBuildSetting(setting):
return "xcodebuild did not return a value for build setting \(setting)"
case let .readFailed(fileURL, underlyingError):
var description = "Failed to read file or folder at \(fileURL.path)"
if let underlyingError = underlyingError {
description += ": \(underlyingError)"
}
return description
case let .writeFailed(fileURL, underlyingError):
var description = "Failed to write to \(fileURL.path)"
if let underlyingError = underlyingError {
description += ": \(underlyingError)"
}
return description
case let .noAvailableSimulators(platformName):
return "Could not find any available simulators for \(platformName)"
case let .incompatibleRequirements(dependency, first, second):
let requirement: (VersionRequirement) -> String = { arg in
let (specifier, fromDependency) = arg
return "\(specifier)" + (fromDependency.map { " (\($0))" } ?? "")
}
return "Could not pick a version for \(dependency), due to mutually incompatible requirements:\n\t\(requirement(first))\n\t\(requirement(second))"
case let .taggedVersionNotFound(dependency):
return "No tagged versions found for \(dependency)"
case let .requiredVersionNotFound(dependency, specifier):
return "No available version for \(dependency) satisfies the requirement: \(specifier)"
case let .unsatisfiableDependencyList(subsetList):
let subsetString = subsetList.map { "\t" + $0 }.joined(separator: "\n")
return "No valid versions could be found that restrict updates to:\n\(subsetString)"
case let .repositoryCheckoutFailed(workingDirectoryURL, reason, underlyingError):
var description = "Failed to check out repository into \(workingDirectoryURL.path): \(reason)"
if let underlyingError = underlyingError {
description += " (\(underlyingError))"
}
return description
case let .parseError(description):
return "Parse error: \(description)"
case let .invalidBinaryJSON(url, error):
return "Unable to parse binary-only framework JSON at \(url) due to error: \(error)"
case let .invalidArchitectures(description):
return "Invalid architecture: \(description)"
case let .invalidUUIDs(description):
return "Invalid architecture UUIDs: \(description)"
case let .missingEnvironmentVariable(variable):
return "Environment variable not set: \(variable)"
case let .noSharedFrameworkSchemes(dependency, platforms):
var description = "Dependency \"\(dependency.name)\" has no shared framework schemes"
if !platforms.isEmpty {
let platformsString = Set(platforms.map { $0.platformSimulatorlessFromHeuristic }).joined(separator: ", ")
description += " for any of the platforms: \(platformsString)"
}
switch dependency {
case let .gitHub(server, repository):
description += "\n\nIf you believe this to be an error, please file an issue with the maintainers at \(server.newIssueURL(for: repository).absoluteString)"
case .git, .binary:
break
}
return description
case let .noSharedSchemes(project, serverAndRepository):
var description = "Project \"\(project)\" has no shared schemes"
if let (server, repository) = serverAndRepository {
description += "\n\nIf you believe this to be an error, please file an issue with the maintainers at \(server.newIssueURL(for: repository).absoluteString)"
}
return description
case let .xcodebuildTimeout(project):
return "xcodebuild timed out while trying to read \(project) 😭"
case let .duplicateDependencies(duplicateDeps):
let deps = duplicateDeps
.sorted() // important to match expected order in test cases
.map { "\n\t" + $0.description }
.joined(separator: "")
return "The following dependencies are duplicates:\(deps)"
case let .dependencyCycle(graph):
let prettyGraph = graph
.map { project, dependencies in
let prettyDependencies = dependencies
.map { $0.name }
.joined(separator: ", ")
return "\(project.name): \(prettyDependencies)"
}
.joined(separator: "\n")
return "The dependency graph contained a cycle:\n\(prettyGraph)"
case let .gitHubAPIRequestFailed(message):
return "GitHub API request failed: \(message)"
case .gitHubAPITimeout:
return "GitHub API timed out"
case let .unknownDependencies(names):
return "No entry found for \(names.count > 1 ? "dependencies" : "dependency") \(names.joined(separator: ", ")) in Cartfile."
case let .unresolvedDependencies(names):
return "No entry found for \(names.count > 1 ? "dependencies" : "dependency") \(names.joined(separator: ", ")) in Cartfile.resolved – "
+ "please run `carthage update` if the dependency is contained in the project's Cartfile."
case let .buildFailed(taskError, log):
var message = "Build Failed\n"
if case let .shellTaskFailed(task, exitCode, _) = taskError {
message += "\tTask failed with exit code \(exitCode):\n"
message += "\t\(task)\n"
} else {
message += "\t" + taskError.description + "\n"
}
message += "\nThis usually indicates that project itself failed to compile."
if let log = log {
message += " Please check the xcodebuild log for more details: \(log.path)"
}
return message
case .unknownFrameworkSwiftVersion(let message):
return message
case let .taskError(taskError):
return taskError.description
case let .internalError(description):
return description
case let .invalidResolvedCartfile(incompatibilities):
var message = "The following incompatibilities were found in Cartfile.resolved:\n"
message += incompatibilities
.sorted { $0.dependency.name < $1.dependency.name }
.flatMap { incompatibility -> [String] in
let sortedRequirements = incompatibility
.incompatibleRequirements
.sorted { $0.0.name < $1.0.name }
return sortedRequirements.map { dependency, version in
return "* \(incompatibility.dependency.name) \(incompatibility.pinnedVersion) is incompatible with \(dependency.name) \(version)"
}
}
.joined(separator: "\n")
return message
case let .duplicatesInArchive(duplicates):
let prettyDupeList = duplicates.dictionary
.map { "* \t\($0.value.map{ url in return url.absoluteString }.joined(separator: "\n\t")) \n\t\tto:\n\t\($0.key)" }
.joined(separator: "\n")
return "Invalid archive - Found multiple frameworks with the same unarchiving destination:\n\(prettyDupeList)"
case let .xcframeworkRequired(info):
let archs = info.commonArchitectures.joined(separator: ", ")
return [
"\(info.underlyingError)",
"Building universal frameworks with common architectures is not possible. " +
"The device and simulator slices for \"\(info.productName)\" both build for: \(archs)",
"Rebuild with --use-xcframeworks to create an xcframework bundle instead."
].joined(separator: "\n")
}
}
}