mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-13 08:43:27 +01:00
Replaces StoreApp.setVersions() preconditionFailure with runtime error
It’s more common than expected for apps to not have any app versions, so better to fail gracefully than crash.
This commit is contained in:
@@ -162,14 +162,12 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
|
||||
|
||||
if let versions = try container.decodeIfPresent([AppVersion].self, forKey: .versions)
|
||||
{
|
||||
//TODO: Throw error if there isn't at least one version.
|
||||
|
||||
for version in versions
|
||||
{
|
||||
version.appBundleID = self.bundleIdentifier
|
||||
}
|
||||
|
||||
self.setVersions(versions)
|
||||
try self.setVersions(versions)
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -187,7 +185,7 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
|
||||
size: Int64(size),
|
||||
appBundleID: self.bundleIdentifier,
|
||||
in: context)
|
||||
self.setVersions([appVersion])
|
||||
try self.setVersions([appVersion])
|
||||
}
|
||||
}
|
||||
catch
|
||||
@@ -204,8 +202,12 @@ public class StoreApp: NSManagedObject, Decodable, Fetchable
|
||||
|
||||
internal extension StoreApp
|
||||
{
|
||||
func setVersions(_ versions: [AppVersion])
|
||||
func setVersions(_ versions: [AppVersion]) throws
|
||||
{
|
||||
guard let latestVersion = versions.first else {
|
||||
throw MergeError.noVersions(for: self)
|
||||
}
|
||||
|
||||
self._versions = NSOrderedSet(array: versions)
|
||||
|
||||
let latestSupportedVersion = versions.first(where: { $0.isSupported })
|
||||
@@ -225,7 +227,6 @@ internal extension StoreApp
|
||||
}
|
||||
|
||||
// Preserve backwards compatibility by assigning legacy property values.
|
||||
guard let latestVersion = versions.first else { preconditionFailure("StoreApp must have at least one AppVersion.") }
|
||||
self.latestVersionString = latestVersion.version
|
||||
self._versionDate = latestVersion.date
|
||||
self._versionDescription = latestVersion.localizedDescription
|
||||
@@ -263,7 +264,7 @@ public extension StoreApp
|
||||
appBundleID: app.bundleIdentifier,
|
||||
sourceID: Source.altStoreIdentifier,
|
||||
in: context)
|
||||
app.setVersions([appVersion])
|
||||
try? app.setVersions([appVersion])
|
||||
|
||||
#if BETA
|
||||
app.isBeta = true
|
||||
|
||||
Reference in New Issue
Block a user