forked from Carthage/Carthage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathErrors.swift
316 lines (233 loc) · 9.98 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
//
// Errors.swift
// Carthage
//
// Created by Justin Spahr-Summers on 2014-10-24.
// Copyright (c) 2014 Carthage. All rights reserved.
//
import Foundation
import ReactiveCocoa
import ReactiveTask
/// Possible errors that can originate from Carthage.
public enum CarthageError: ErrorType, Equatable {
/// 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(ProjectIdentifier, VersionSpecifier, VersionSpecifier)
/// No tagged versions could be found for the dependency.
case TaggedVersionNotFound(ProjectIdentifier)
/// No existent version could be found to satisfy the version specifier for
/// a dependency.
case RequiredVersionNotFound(ProjectIdentifier, VersionSpecifier)
/// Failed to check out a repository.
case RepositoryCheckoutFailed(workingDirectoryURL: NSURL, reason: String, underlyingError: NSError?)
/// Failed to read a file or directory at the given URL.
case ReadFailed(NSURL, NSError?)
/// Failed to write a file or directory at the given URL.
case WriteFailed(NSURL, NSError?)
/// An error occurred parsing a Carthage file.
case ParseError(description: String)
// 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)
/// An error occurred when parsing the contents of a framework's Info.plist.
case InfoPlistParseFailed(plistURL: NSURL, reason: String)
/// The project is not sharing any framework schemes, so Carthage cannot
/// discover them.
case NoSharedFrameworkSchemes(ProjectIdentifier, Set<Platform>)
/// The project is not sharing any schemes, so Carthage cannot discover
/// them.
case NoSharedSchemes(ProjectLocator, GitHubRepository?)
/// Timeout whilst running `xcodebuild list` to enumerate shared schemes.
case XcodebuildListTimeout(ProjectLocator, GitHubRepository?)
/// A cartfile contains duplicate dependencies, either in itself or across
/// other cartfiles.
case DuplicateDependencies([DuplicateDependency])
/// A request to the GitHub API failed due to authentication or rate-limiting.
case GitHubAPIRequestFailed(String)
/// An error occurred while shelling out.
case TaskError(ReactiveTaskError)
/// An error occurred in a network operation.
case NetworkError(NSError)
}
public func == (lhs: CarthageError, rhs: CarthageError) -> Bool {
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 (.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 (.MissingEnvironmentVariable(left), .MissingEnvironmentVariable(right)):
return left == right
case let (.InvalidArchitectures(left), .InvalidArchitectures(right)):
return left == right
case let (.InfoPlistParseFailed(la, lb), .InfoPlistParseFailed(ra, rb)):
return la == ra && lb == rb
case let (.NoSharedFrameworkSchemes(la, lb), .NoSharedFrameworkSchemes(ra, rb)):
return la == ra && lb == rb
case let (.NoSharedSchemes(la, lb), .NoSharedSchemes(ra, rb)):
return la == ra && lb == rb
case let (.DuplicateDependencies(left), .DuplicateDependencies(right)):
return left.sort() == right.sort()
case let (.GitHubAPIRequestFailed(left), .GitHubAPIRequestFailed(right)):
return left == right
case (.TaskError, .TaskError):
// TODO: Implement Equatable in ReactiveTask.
return false
case let (.NetworkError(left), .NetworkError(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 .IncompatibleRequirements(dependency, first, second):
return "Could not pick a version for \(dependency), due to mutually incompatible requirements:\n\t\(first)\n\t\(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 .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 .InvalidArchitectures(description):
return "Invalid architecture: \(description)"
case let .InvalidUUIDs(description):
return "Invalid architecture UUIDs: \(description)"
case let .InfoPlistParseFailed(plistURL, reason):
return "Failed to parse the framework Info.plist file at \(plistURL.path!): \(reason)"
case let .MissingEnvironmentVariable(variable):
return "Environment variable not set: \(variable)"
case let .NoSharedFrameworkSchemes(projectIdentifier, platforms):
var description = "Dependency \"\(projectIdentifier.name)\" has no shared framework schemes"
if !platforms.isEmpty {
let platformsString = platforms.map { $0.description }.joinWithSeparator(", ")
description += " for any of the platforms: \(platformsString)"
}
switch projectIdentifier {
case let .GitHub(repository):
description += "\n\nIf you believe this to be an error, please file an issue with the maintainers at \(repository.newIssueURL.absoluteString)"
case .Git:
break
}
return description
case let .NoSharedSchemes(project, repository):
var description = "Project \"\(project)\" has no shared schemes"
if let repository = repository {
description += "\n\nIf you believe this to be an error, please file an issue with the maintainers at \(repository.newIssueURL.absoluteString)"
}
return description
case let .XcodebuildListTimeout(project, repository):
var description = "Failed to discover shared schemes in project \(project)—either the project does not have any shared schemes, or xcodebuild never returned"
if let repository = repository {
description += "\n\nIf you believe this to be a project configuration error, please file an issue with the maintainers at \(repository.newIssueURL.absoluteString)"
}
return description
case let .DuplicateDependencies(duplicateDeps):
let deps = duplicateDeps.sort() // important to match expected order in test cases
.reduce("") { (acc, dep) in
"\(acc)\n\t\(dep)"
}
return "The following dependencies are duplicates:\(deps)"
case let .GitHubAPIRequestFailed(message):
return "GitHub API request failed: \(message)"
case let .TaskError(taskError):
return taskError.description
case let .NetworkError(error):
return error.description
}
}
}
/// A duplicate dependency, used in CarthageError.DuplicateDependencies.
public struct DuplicateDependency: Comparable {
/// The duplicate dependency as a project.
public let project: ProjectIdentifier
/// The locations where the dependency was found as duplicate.
public let locations: [String]
// The generated memberwise initialiser has internal access control and
// cannot be used in test cases, so we reimplement it as public. We are also
// sorting locations, which makes sure that we can match them in a
// test case.
public init(project: ProjectIdentifier, locations: [String]) {
self.project = project
self.locations = locations.sort(<)
}
}
extension DuplicateDependency: CustomStringConvertible {
public var description: String {
return "\(project) \(printableLocations)"
}
private var printableLocations: String {
if locations.count == 0 {
return ""
}
return "(found in "
+ locations.joinWithSeparator(" and ")
+ ")"
}
}
public func == (lhs: DuplicateDependency, rhs: DuplicateDependency) -> Bool {
return lhs.project == rhs.project && lhs.locations == rhs.locations
}
public func < (lhs: DuplicateDependency, rhs: DuplicateDependency) -> Bool {
if lhs.description < rhs.description {
return true
}
if lhs.locations.count < rhs.locations.count {
return true
}
else if lhs.locations.count > rhs.locations.count {
return false
}
for (lhsLocation, rhsLocation) in zip(lhs.locations, rhs.locations) {
if lhsLocation < rhsLocation {
return true
}
else if lhsLocation > rhsLocation {
return false
}
}
return false
}