Skip to content

Commit ed1aebf

Browse files
Refactored DecodingError.dataCorrupted calls into a helper function
1 parent 5eba8e1 commit ed1aebf

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

Sources/DynamicCodable/DynamicCodableDecoder.swift

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,7 @@ extension DynamicCodableDecoder.Decoder: Swift.Decoder {
184184
@inline(__always)
185185
func validate<T: BinaryFloatingPoint>(_ floatingPoint: T, originalValue: CustomStringConvertible) throws -> T {
186186
guard floatingPoint.isFinite else {
187-
throw DecodingError.dataCorrupted(
188-
.init(
189-
codingPath: codingPath,
190-
debugDescription: "Represented number <\(floatingPoint)> does not fit in \(T.self)."
191-
)
192-
)
187+
throw dataCorruptedError("Represented number <\(floatingPoint)> does not fit in \(T.self).")
193188
}
194189

195190
return floatingPoint
@@ -260,12 +255,7 @@ extension DynamicCodableDecoder.Decoder: Swift.Decoder {
260255
@inline(__always)
261256
func validate<T: FixedWidthInteger>(_ fixedWidthInteger: T?, originalValue: CustomStringConvertible) throws -> T {
262257
guard let fixedWidthInteger = fixedWidthInteger else {
263-
throw DecodingError.dataCorrupted(
264-
.init(
265-
codingPath: codingPath,
266-
debugDescription: "Represented number <\(originalValue)> does not fit in \(T.self)."
267-
)
268-
)
258+
throw dataCorruptedError("Represented number <\(originalValue)> does not fit in \(T.self).")
269259
}
270260

271261
return fixedWidthInteger
@@ -303,6 +293,15 @@ extension DynamicCodableDecoder.Decoder: Swift.Decoder {
303293
)
304294
)
305295
}
296+
297+
private func dataCorruptedError(_ debugDescription: String) -> DecodingError {
298+
DecodingError.dataCorrupted(
299+
.init(
300+
codingPath: codingPath,
301+
debugDescription: debugDescription
302+
)
303+
)
304+
}
306305
}
307306

308307
extension DynamicCodableDecoder.Decoder {

0 commit comments

Comments
 (0)