-0.4 C
New York
Saturday, February 22, 2025

swift – Error with decoder on CI – Run Checks for iOS


I’ve a decoding take a look at of a knowledge mannequin that runs tremendous and with out errors in Xcode however within the server fails and I can not discover the trigger, are you able to give me a hand if somebody is aware of how I can establish/clear up the failure on the server? I connect the picture of the log of the CI assessments the place you’ll be able to see the error and the code in query.
I admire upfront any opinion on this matter. Thanks!

SFBConfigModel:

inner struct SFBConfigModel: Codable {
    var config: SFBIntervalModel
    var binding: SFBBindingModel?
    
    non-public enum CodingKeys: String, CodingKey {
        case config
        case binding
    }
    
    init(
        config: SFBIntervalModel,
        binding: SFBBindingModel?
    ) {
        self.config = config
        self.binding = binding
    }

    init(from decoder: Decoder) throws {
        let container = attempt decoder.container(keyedBy: CodingKeys.self)

        // Searches for the config worth which LocalStorage can assist.
        self.config = attempt container.decode(SFBIntervalModel.self, forKey: .config)

        if let binding = attempt? container.decode(SFBBindingModel.self, forKey: .binding) {
            self.binding = binding
        }
    }

}

El take a look at:

            context("when creating the mannequin with a invalid json") {
                it("then you definitely get a decode error") {
                    // Given
                    let JSONData = """
                    {
                        "config": {
                            "interval_time_in_minutes": "thisIsAnUnexpectedTypeOfValue"
                        },
                        "binding": {
                            "seed": "thisIsOtherFakeSeed",
                            "device_id": "thisIsOtherFakeDeviceID"
                        }
                    }
                    """.knowledge(utilizing: .utf8)!
                    let decoder = JSONDecoderMock()
                    var mannequin: SFBConfigModel!
                    
                    do {
                        // When
                        mannequin = attempt decoder.decode(
                            SFBConfigModel.self,
                            from: JSONData
                        )
                    } catch {
                        // Then
                        count on("(error)").to(comprise("JSONDecoderErrorDomainMock"))
                    }
                }
            }

JSONDecoderMock:

    non-public class JSONDecoderMock: JSONDecoder {
        var decodeCalled = false

        override func decode(_ kind: T.Kind, from knowledge: Knowledge) throws -> T the place T : Decodable {
            decodeCalled = true
            throw NSError(area: "JSONDecoderErrorDomainMock", code: -1, userInfo: nil)
        }
    }

Picture of the error on the server that doesn’t happen regionally:

Image of the error on the server that does not occur locally

I’ve modified the way in which of decoding, I added a mock however the error persists despite the fact that it doesn’t play regionally.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles