Provide more context when failing to search for mapping models #299

This commit is contained in:
John Estropia
2019-01-11 19:48:35 +09:00
parent 8c30ec3a3d
commit 42d1f41939
4 changed files with 12 additions and 6 deletions

View File

@@ -31,6 +31,7 @@ import Foundation
/**
A `SchemaMappingProvider` that tries to infer model migration between two `DynamicSchema` versions by searching all `xcmappingmodel`s from `Bundle.allBundles` or by relying on lightweight migration if possible. Throws an error if lightweight migration is impossible for the two `DynamicSchema`. This mapping is automatically used as a fallback mapping provider, even if no mapping providers are explicitly declared in the `StorageInterface`.
- Note: For security reasons, `InferredSchemaMappingProvider` will not search `Bundle.allFrameworks` by default. If the `xcmappingmodel`s are bundled within a framework, use `XcodeSchemaMappingProvider` instead and provide `Bundle(for: <a class in the framework>` to its initializer.
*/
public final class InferredSchemaMappingProvider: Hashable, SchemaMappingProvider {
@@ -53,7 +54,7 @@ public final class InferredSchemaMappingProvider: Hashable, SchemaMappingProvide
// MARK: SchemaMappingProvider
public func cs_createMappingModel(from sourceSchema: DynamicSchema, to destinationSchema: DynamicSchema, storage: LocalStorage) throws -> (mappingModel: NSMappingModel, migrationType: MigrationType) {
let sourceModel = sourceSchema.rawModel()
let destinationModel = destinationSchema.rawModel()
@@ -85,8 +86,13 @@ public final class InferredSchemaMappingProvider: Hashable, SchemaMappingProvide
)
}
catch {
throw CoreStoreError(error)
let coreStoreError = CoreStoreError(error)
CoreStore.log(
coreStoreError,
"\(cs_typeName(self)) failed to find migration mappings from version model \"\(sourceSchema.modelVersion)\" to \"\(destinationSchema.modelVersion)\" in the \(cs_typeName(storage)) at URL \"\(storage.fileURL)\". The local storage may be corrupt or the \(cs_typeName(storage)) initializer may be missing the correct \(cs_typeName(SchemaMappingProvider.self))"
)
throw coreStoreError
}
}
}