This code crashes in the beta branch:
import CodableKit
import Foundation
_ = UUID.properties()
Producing the following error:
Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: Swift.DecodingError.dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "Attempted to decode UUID from invalid UUID string.", underlyingError: nil))
This also happens whenever Decodable.properties() is called on a type that has a UUID field.
This happens because CodingKeyCollector works by pretending to decode a type. When it encounters a String, it tries to decode "0":
func decode(_ type: String.Type) throws -> String {
result.add(type: type, atPath: codingPath)
return "0"
}
I was able to temporarily fix the crasher by changing that function in CodingKeyCollectorSingleValueDecoder to:
func decode(_ type: String.Type) throws -> String {
result.add(type: type, atPath: codingPath)
return "00000000-0000-0000-0000-000000000000"
}
A slightly more robust solution is to add a decode(_ type: UUID.Type) -> UUID that handles that special case.
Still, this only fixes this one case and doesn't address the class of potential errors that arise from assuming that any Decodable can be successfully decoded with an arbitrary combination of values (false, "0", 0).
This code crashes in the beta branch:
Producing the following error:
This also happens whenever
Decodable.properties()is called on a type that has a UUID field.This happens because
CodingKeyCollectorworks by pretending to decode a type. When it encounters aString, it tries to decode"0":I was able to temporarily fix the crasher by changing that function in
CodingKeyCollectorSingleValueDecoderto:A slightly more robust solution is to add a
decode(_ type: UUID.Type) -> UUIDthat handles that special case.Still, this only fixes this one case and doesn't address the class of potential errors that arise from assuming that any
Decodablecan be successfully decoded with an arbitrary combination of values (false,"0",0).