vapor / sqlite-kit

Non-blocking SQLite client library with SQL builder built on SwiftNIO
MIT License
63 stars 31 forks source link

Why is SQLiteDataEncoder._Encoder is not supporting unkeyedContainer() #62

Closed jochenkiene closed 4 years ago

jochenkiene commented 4 years ago

Vapor just crashes if I have some data fields with some Arrays. fatalError() doesn’t give a descriptive error.

jochenkiene commented 4 years ago

I added this for a workaround, which solved the problem:

    private struct _UnkeyedValueEncoder: UnkeyedEncodingContainer {
        var count: Int {
            return 0
        }

        mutating func encodeNil() throws {
            throw DoJSON()
        }

        mutating func nestedContainer<NestedKey>(keyedBy keyType: NestedKey.Type) -> KeyedEncodingContainer<NestedKey> where NestedKey : CodingKey {
            fatalError()
        }

        mutating func nestedUnkeyedContainer() -> UnkeyedEncodingContainer {
            return self
        }

        mutating func superEncoder() -> Encoder {
            return encoder
        }

        var codingPath: [CodingKey] {
            return self.encoder.codingPath
        }

        let encoder: _Encoder

        init(_ encoder: _Encoder) {
            self.encoder = encoder
        }

        mutating func encode<T>(_ value: T) throws where T : Encodable {
            throw DoJSON()
        }
    }