diff --git a/Sources/DynamicCodable/DynamicCodableDecoder.swift b/Sources/DynamicCodable/DynamicCodableDecoder.swift index 714d50e..c745acf 100644 --- a/Sources/DynamicCodable/DynamicCodableDecoder.swift +++ b/Sources/DynamicCodable/DynamicCodableDecoder.swift @@ -184,12 +184,7 @@ extension DynamicCodableDecoder.Decoder: Swift.Decoder { @inline(__always) func validate(_ floatingPoint: T, originalValue: CustomStringConvertible) throws -> T { guard floatingPoint.isFinite else { - throw DecodingError.dataCorrupted( - .init( - codingPath: codingPath, - debugDescription: "Represented number <\(floatingPoint)> does not fit in \(T.self)." - ) - ) + throw dataCorruptedError("Represented number <\(floatingPoint)> does not fit in \(T.self).") } return floatingPoint @@ -260,12 +255,7 @@ extension DynamicCodableDecoder.Decoder: Swift.Decoder { @inline(__always) func validate(_ fixedWidthInteger: T?, originalValue: CustomStringConvertible) throws -> T { guard let fixedWidthInteger = fixedWidthInteger else { - throw DecodingError.dataCorrupted( - .init( - codingPath: codingPath, - debugDescription: "Represented number <\(originalValue)> does not fit in \(T.self)." - ) - ) + throw dataCorruptedError("Represented number <\(originalValue)> does not fit in \(T.self).") } return fixedWidthInteger @@ -303,6 +293,15 @@ extension DynamicCodableDecoder.Decoder: Swift.Decoder { ) ) } + + private func dataCorruptedError(_ debugDescription: String) -> DecodingError { + DecodingError.dataCorrupted( + .init( + codingPath: codingPath, + debugDescription: debugDescription + ) + ) + } } extension DynamicCodableDecoder.Decoder {