💣 Fail fast if regular expression can not be initialized

This commit is contained in:
Chris Araman 2021-04-21 22:20:06 -07:00
parent a27cc68d2c
commit 6a12b3096f
No known key found for this signature in database
GPG key ID: BB4499D9E11B61E0

View file

@ -12,11 +12,11 @@ import Version
/// Manages searching the MAS catalog through the iTunes Search and Lookup APIs.
class MasStoreSearch: StoreSearch {
private let networkManager: NetworkManager
private static let versionExpression: NSRegularExpression? = {
private static let versionExpression: NSRegularExpression = {
do {
return try NSRegularExpression(pattern: #"\"versionDisplay\"\:\"([^\"]+)\""#)
} catch {
return nil
fatalError("Unexpected error initializing NSRegularExpression: \(error.localizedDescription)")
}
}()
@ -125,7 +125,7 @@ class MasStoreSearch: StoreSearch {
let html = String(decoding: data, as: UTF8.self)
let fullRange = NSRange(html.startIndex..<html.endIndex, in: html)
guard let match = MasStoreSearch.versionExpression?.firstMatch(in: html, range: fullRange),
guard let match = MasStoreSearch.versionExpression.firstMatch(in: html, range: fullRange),
let range = Range(match.range(at: 1), in: html),
let version = Version(tolerant: html[range])
else {