CodableWrappers icon indicating copy to clipboard operation
CodableWrappers copied to clipboard

`DateFormatterStaticDecoder` throws `valueNotFound` error instead of `dataCorrupted` error

Open Brett-Best opened this issue 3 years ago • 0 comments

https://github.com/GottaGetSwifty/CodableWrappers/blob/4eb46a4c656333e8514db8aad204445741de7d40/Sources/CodableWrappers/StaticCoders/DateCoding.swift#L60-L71 I was debugging an issue which was made a bit confusing because of throwing valueNotFound, would you like me to make a PR changing this to a dataCorrupted error?

It would match the behaviour of:

import Foundation

let string = """
{ "date": "ehrtrthrt" }
"""

struct Model: Codable {
  let date: Date
}

let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601

do {
  let model = try decoder.decode(Model.self, from: Data(string.utf8))
} catch {
  if case DecodingError.dataCorrupted = error {
    print("DecodingError is dataCorrupted")
  } else {
    // not called
  }
}

Brett-Best avatar Aug 18 '22 18:08 Brett-Best