Decoder error added for unexpected type
This commit is contained in:
parent
9dde688feb
commit
fe12f6855d
@ -18,6 +18,7 @@ public struct ModelRegistry {
|
|||||||
case decoderOther(message: String)
|
case decoderOther(message: String)
|
||||||
case decoderErrorObjectNotPresent(codingKey: CodingKey, codingPath: [CodingKey])
|
case decoderErrorObjectNotPresent(codingKey: CodingKey, codingPath: [CodingKey])
|
||||||
case decoderErrorModelNotMapped(identifer: String? = nil, codingKey: CodingKey? = nil, codingPath: [CodingKey]? = nil)
|
case decoderErrorModelNotMapped(identifer: String? = nil, codingKey: CodingKey? = nil, codingPath: [CodingKey]? = nil)
|
||||||
|
case decoderErrorUnexpectedType(actualType: String? = nil, expectedType: String? = nil, identifer: String? = nil, codingKey: CodingKey? = nil, codingPath: [CodingKey]? = nil)
|
||||||
case duplicateRegistration(message: String)
|
case duplicateRegistration(message: String)
|
||||||
case other(message: String)
|
case other(message: String)
|
||||||
case handlerNotMapped(identifer: String? = nil, categoryName: String? = nil)
|
case handlerNotMapped(identifer: String? = nil, categoryName: String? = nil)
|
||||||
@ -90,6 +91,10 @@ public struct ModelRegistry {
|
|||||||
errorObject.title = "Decoder Error: Model Not Mapped"
|
errorObject.title = "Decoder Error: Model Not Mapped"
|
||||||
let codingPathConcat = codingPath?.compactMap { $0.stringValue }.joined(separator: " ") ?? ""
|
let codingPathConcat = codingPath?.compactMap { $0.stringValue }.joined(separator: " ") ?? ""
|
||||||
errorObject.messageToLog = (identifer ?? "") + (codingKey?.stringValue ?? "") + codingPathConcat
|
errorObject.messageToLog = (identifer ?? "") + (codingKey?.stringValue ?? "") + codingPathConcat
|
||||||
|
case .decoderErrorUnexpectedType(let actualType, let expectedType, let identifer, let codingKey, let codingPath):
|
||||||
|
errorObject.title = "Decoder Error: Model Type Unexpected"
|
||||||
|
let codingPathConcat = codingPath?.compactMap { $0.stringValue }.joined(separator: " ") ?? ""
|
||||||
|
errorObject.messageToLog = "Actual Type: \(actualType ?? "") Expected Type: \(expectedType ?? "")" + (identifer ?? "") + (codingKey?.stringValue ?? "") + codingPathConcat
|
||||||
case .handlerNotMapped(let identifer, let categoryName):
|
case .handlerNotMapped(let identifer, let categoryName):
|
||||||
errorObject.title = "Handler Not Mapped"
|
errorObject.title = "Handler Not Mapped"
|
||||||
errorObject.messageToLog = (identifer ?? "") + (categoryName ?? "")
|
errorObject.messageToLog = (identifer ?? "") + (categoryName ?? "")
|
||||||
@ -384,7 +389,7 @@ public extension UnkeyedDecodingContainer {
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
MVMCoreLoggingHandler.logDebugMessage(withDelegate: logMessage)
|
MVMCoreLoggingHandler.logDebugMessage(withDelegate: logMessage)
|
||||||
throw ModelRegistry.Error.decoderErrorModelNotMapped(identifer: identifier, codingKey: typeCodingKey, codingPath: nestedContainer.codingPath)
|
throw ModelRegistry.Error.decoderErrorUnexpectedType(actualType: "\(mirror.subjectType)", expectedType: typeName, identifer: identifier, codingKey: typeCodingKey, codingPath: nestedContainer.codingPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -32,6 +32,9 @@ extension ModelRegistry.Error: HumanReadableDecodingErrorProtocol {
|
|||||||
case .decoderErrorModelNotMapped(let identifier, let codingKey, let codingPath) where identifier != nil && codingKey != nil && codingPath != nil:
|
case .decoderErrorModelNotMapped(let identifier, let codingKey, let codingPath) where identifier != nil && codingKey != nil && codingPath != nil:
|
||||||
return "Model identifier \"\(identifier!)\" is not mapped for \"\(codingKey!.stringValue)\" @ \(codingPath!.map { return $0.stringValue })"
|
return "Model identifier \"\(identifier!)\" is not mapped for \"\(codingKey!.stringValue)\" @ \(codingPath!.map { return $0.stringValue })"
|
||||||
|
|
||||||
|
case .decoderErrorUnexpectedType(let actualType, let expectedType, let identifier, let codingKey, let codingPath) where actualType != nil && expectedType != nil && identifier != nil && codingKey != nil && codingPath != nil:
|
||||||
|
return "Model identifier \"\(identifier!)\" has unexpected type \"\(actualType!)\" expected type \"\(expectedType!)\" for \"\(codingKey!.stringValue)\" @ \(codingPath!.map { return $0.stringValue })"
|
||||||
|
|
||||||
case .decoderErrorObjectNotPresent(let codingKey, let codingPath):
|
case .decoderErrorObjectNotPresent(let codingKey, let codingPath):
|
||||||
return "Required model \"\(codingKey.stringValue)\" was not found @ \(codingPath.map { return $0.stringValue })"
|
return "Required model \"\(codingKey.stringValue)\" was not found @ \(codingPath.map { return $0.stringValue })"
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user