Type casting failed error fixed.
This commit is contained in:
parent
3e1581e28e
commit
9dde688feb
@ -365,11 +365,26 @@ public extension UnkeyedDecodingContainer {
|
||||
}
|
||||
// Now get the decoder to use for the type
|
||||
let decoder = try self.superDecoder()
|
||||
if let model = try type.init(from: decoder) as? T {
|
||||
let model = try type.init(from: decoder)
|
||||
|
||||
if let model = model as? T {
|
||||
models.append(model)
|
||||
} else {
|
||||
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "ModelRegistry Error decoderError: \(typeCodingKey)")
|
||||
throw ModelRegistry.Error.decoderError
|
||||
let typeName = "\(T.self)".components(separatedBy: "&").last?.trimmingCharacters(in: .whitespaces) ?? "\(T.self)"
|
||||
let mirror = Mirror(reflecting: model)
|
||||
|
||||
let logMessage = """
|
||||
ModelRegistry Error:
|
||||
Model Type Casting Failed:
|
||||
- Attempted to cast value of type '\(mirror.subjectType)' to '\(typeName)'.
|
||||
- Molecule Identifier: '\(identifier)'
|
||||
- Debug Context:
|
||||
Actual Type: '\(mirror.subjectType)'
|
||||
Expected Type: '\(typeName)'
|
||||
"""
|
||||
|
||||
MVMCoreLoggingHandler.logDebugMessage(withDelegate: logMessage)
|
||||
throw ModelRegistry.Error.decoderErrorModelNotMapped(identifer: identifier, codingKey: typeCodingKey, codingPath: nestedContainer.codingPath)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user