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

@@ -50,7 +50,7 @@ public final class CSDataStack: NSObject, CoreStoreObjectiveCType {
Initializes a `CSDataStack` from the model with the specified `modelName` in the specified `bundle`.
- parameter xcodeModelName: the name of the (.xcdatamodeld) model file. If not specified, the application name (CFBundleName) will be used if it exists, or "CoreData" if it the bundle name was not set.
- parameter bundle: an optional bundle to load models from. If not specified, the main bundle will be used.
- parameter bundle: an optional bundle to load .xcdatamodeld models from. If not specified, the main bundle will be used.
- parameter versionChain: the version strings that indicate the sequence of model versions to be used as the order for progressive migrations. If not specified, will default to a non-migrating data stack.
*/
@objc

View File

@@ -43,7 +43,7 @@ public final class DataStack: Equatable {
Convenience initializer for `DataStack` that creates a `SchemaHistory` from the model with the specified `modelName` in the specified `bundle`.
- parameter xcodeModelName: the name of the (.xcdatamodeld) model file. If not specified, the application name (CFBundleName) will be used if it exists, or "CoreData" if it the bundle name was not set (e.g. in Unit Tests).
- parameter bundle: an optional bundle to load models from. If not specified, the main bundle will be used.
- parameter bundle: an optional bundle to load .xcdatamodeld models from. If not specified, the main bundle will be used.
- parameter migrationChain: the `MigrationChain` that indicates the sequence of model versions to be used as the order for progressive migrations. If not specified, will default to a non-migrating data stack.
*/
public convenience init(xcodeModelName: XcodeDataModelFileName = DataStack.applicationName, bundle: Bundle = Bundle.main, migrationChain: MigrationChain = nil) {

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
}
}
}

View File

@@ -42,7 +42,7 @@ public final class XcodeDataModelSchema: DynamicSchema {
/**
Creates a `XcodeDataModelSchema` for each of the models declared in the specified (.xcdatamodeld) model file.
- parameter modelName: the name of the (.xcdatamodeld) model file. If not specified, the application name (CFBundleName) will be used if it exists, or "CoreData" if it the bundle name was not set.
- parameter bundle: an optional bundle to load models from. If not specified, the main bundle will be used.
- parameter bundle: an optional bundle to load .xcdatamodeld models from. If not specified, the main bundle will be used.
- parameter migrationChain: the `MigrationChain` that indicates the sequence of model versions to be used as the order for progressive migrations. If not specified, will default to a non-migrating data stack.
- returns: a tuple containing all `XcodeDataModelSchema` for the models declared in the specified .xcdatamodeld file, and the current model version string declared or inferred from the file.
*/