mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-18 23:44:14 +01:00
Added new error for cases when addStorageAndWait() is used with .allowSynchronousLightweightMigration but migrations are only allowed asynchronously (related to #277)
This commit is contained in:
@@ -217,6 +217,17 @@ extension CoreStoreError: CoreStoreSwiftType, _ObjectiveCBridgeableError {
|
||||
return
|
||||
}
|
||||
self = .progressiveMigrationRequired(localStoreURL: localStoreURL)
|
||||
|
||||
case .asynchronousMigrationRequired:
|
||||
guard
|
||||
let localStoreURL = info["localStoreURL"] as? URL,
|
||||
case let nsError as NSError = info["NSError"]
|
||||
else {
|
||||
|
||||
self = .unknown
|
||||
return
|
||||
}
|
||||
self = .asynchronousMigrationRequired(localStoreURL: localStoreURL, NSError: nsError)
|
||||
|
||||
case .internalError:
|
||||
guard case let nsError as NSError = info["NSError"] else {
|
||||
|
||||
@@ -137,6 +137,10 @@ extension CoreStoreError: CustomDebugStringConvertible, CoreStoreDebugStringConv
|
||||
case .progressiveMigrationRequired(let localStoreURL):
|
||||
firstLine = ".progressiveMigrationRequired"
|
||||
info.append(("localStoreURL", localStoreURL))
|
||||
|
||||
case .asynchronousMigrationRequired(let localStoreURL):
|
||||
firstLine = ".asynchronousMigrationRequired"
|
||||
info.append(("localStoreURL", localStoreURL))
|
||||
|
||||
case .internalError(let NSError):
|
||||
firstLine = ".internalError"
|
||||
|
||||
@@ -53,6 +53,11 @@ public enum CoreStoreError: Error, CustomNSError, Hashable {
|
||||
Progressive migrations are disabled for a store, but an `NSMappingModel` could not be found for a specific source and destination model versions.
|
||||
*/
|
||||
case progressiveMigrationRequired(localStoreURL: URL)
|
||||
|
||||
/**
|
||||
The `LocalStorage` was configured with `.allowSynchronousLightweightMigration`, but the model can only be migrated asynchronously.
|
||||
*/
|
||||
case asynchronousMigrationRequired(localStoreURL: URL, NSError: NSError)
|
||||
|
||||
/**
|
||||
An internal SDK call failed with the specified `NSError`.
|
||||
@@ -92,6 +97,9 @@ public enum CoreStoreError: Error, CustomNSError, Hashable {
|
||||
|
||||
case .progressiveMigrationRequired:
|
||||
return CoreStoreErrorCode.progressiveMigrationRequired.rawValue
|
||||
|
||||
case .asynchronousMigrationRequired:
|
||||
return CoreStoreErrorCode.asynchronousMigrationRequired.rawValue
|
||||
|
||||
case .internalError:
|
||||
return CoreStoreErrorCode.internalError.rawValue
|
||||
@@ -127,6 +135,12 @@ public enum CoreStoreError: Error, CustomNSError, Hashable {
|
||||
return [
|
||||
"localStoreURL": localStoreURL
|
||||
]
|
||||
|
||||
case .asynchronousMigrationRequired(let localStoreURL, let nsError):
|
||||
return [
|
||||
"localStoreURL": localStoreURL,
|
||||
"NSError": nsError
|
||||
]
|
||||
|
||||
case .internalError(let nsError):
|
||||
return [
|
||||
@@ -161,6 +175,10 @@ public enum CoreStoreError: Error, CustomNSError, Hashable {
|
||||
|
||||
case (.progressiveMigrationRequired(let url1), .progressiveMigrationRequired(let url2)):
|
||||
return url1 == url2
|
||||
|
||||
case (.asynchronousMigrationRequired(let url1, let NSError1), .asynchronousMigrationRequired(let url2, let NSError2)):
|
||||
return url1 == url2
|
||||
&& NSError1.isEqual(NSError2)
|
||||
|
||||
case (.internalError(let NSError1), .internalError(let NSError2)):
|
||||
return NSError1.isEqual(NSError2)
|
||||
@@ -205,6 +223,10 @@ public enum CoreStoreError: Error, CustomNSError, Hashable {
|
||||
case .progressiveMigrationRequired(let localStoreURL):
|
||||
hasher.combine(localStoreURL)
|
||||
|
||||
case .asynchronousMigrationRequired(let localStoreURL, let nsError):
|
||||
hasher.combine(localStoreURL)
|
||||
hasher.combine(nsError)
|
||||
|
||||
case .internalError(let nsError):
|
||||
hasher.combine(nsError)
|
||||
|
||||
@@ -261,6 +283,11 @@ public enum CoreStoreErrorCode: Int {
|
||||
Progressive migrations are disabled for a store, but an `NSMappingModel` could not be found for a specific source and destination model versions.
|
||||
*/
|
||||
case progressiveMigrationRequired
|
||||
|
||||
/**
|
||||
The `LocalStorage` was configured with `.allowSynchronousLightweightMigration`, but the model can only be migrated asynchronously.
|
||||
*/
|
||||
case asynchronousMigrationRequired
|
||||
|
||||
/**
|
||||
An internal SDK call failed with the specified "NSError" userInfo key.
|
||||
|
||||
@@ -345,6 +345,18 @@ public final class DataStack: Equatable {
|
||||
)
|
||||
return storage
|
||||
}
|
||||
catch let error as NSError where storage.localStorageOptions.contains(.allowSynchronousLightweightMigration) && error.isCoreDataMigrationError {
|
||||
|
||||
let storeError = CoreStoreError.asynchronousMigrationRequired(
|
||||
localStoreURL: fileURL,
|
||||
NSError: error
|
||||
)
|
||||
CoreStore.log(
|
||||
storeError,
|
||||
"Failed to add \(cs_typeName(storage)) to the stack."
|
||||
)
|
||||
throw storeError
|
||||
}
|
||||
}
|
||||
catch {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user