forked from Carthage/Carthage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BinaryJSONError.swift
55 lines (42 loc) · 1.34 KB
/
BinaryJSONError.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
import Foundation
/// Error parsing a binary-only framework JSON file, used in CarthageError.invalidBinaryJSON.
public enum BinaryJSONError: Error {
/// Unable to parse the JSON.
case invalidJSON(Error)
/// Unable to parse a semantic version from a framework entry.
case invalidVersion(ScannableError)
/// Unable to parse a URL from a framework entry.
case invalidURL(String)
/// URL is non-HTTPS
case nonHTTPSURL(URL)
}
extension BinaryJSONError: CustomStringConvertible {
public var description: String {
switch self {
case let .invalidJSON(error):
return "invalid JSON: \(error)"
case let .invalidVersion(error):
return "unable to parse semantic version: \(error)"
case let .invalidURL(string):
return "invalid URL: \(string)"
case let .nonHTTPSURL(url):
return "specified URL '\(url)' must be HTTPS"
}
}
}
extension BinaryJSONError: Equatable {
public static func == (lhs: BinaryJSONError, rhs: BinaryJSONError) -> Bool {
switch (lhs, rhs) {
case let (.invalidJSON(left), .invalidJSON(right)):
return (left as NSError) == (right as NSError)
case let (.invalidVersion(left), .invalidVersion(right)):
return left == right
case let (.invalidURL(left), .invalidURL(right)):
return left == right
case let (.nonHTTPSURL(left), .nonHTTPSURL(right)):
return left == right
default:
return false
}
}
}