Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken SDK CORE BUG in Decoder #70

Closed
bukira opened this issue Nov 18, 2024 · 2 comments · Fixed by #71
Closed

Broken SDK CORE BUG in Decoder #70

bukira opened this issue Nov 18, 2024 · 2 comments · Fixed by #71
Assignees
Labels
bug Something isn't working

Comments

@bukira
Copy link

bukira commented Nov 18, 2024

decoding(Swift.DecodingError.keyNotFound(CodingKeys(stringValue: "transient", intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: "transient", intValue: nil) ("transient").",

Transient should be option key for decoder in

public struct Traits: Codable, Sendable {
    public let traits: [Trait]
    public let identifier: String?
    public let flags: [Flag]
    public let transient: Bool?
    
    init(traits: [Trait], identifier: String?, flags: [Flag] = [], transient: Bool = false) {
        self.traits = traits
        self.identifier = identifier
        self.flags = flags
        self.transient = transient
    }

    public func encode(to encoder: any Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(traits, forKey: .traits)
        try container.encode(identifier, forKey: .identifier)
        try container.encode(transient, forKey: .transient)
    }
}
public struct Identity: Decodable, Sendable {
    enum CodingKeys: String, CodingKey {
        case flags
        case traits
        case transient
    }

    public let flags: [Flag]
    public let traits: [Trait]
    public let transient: Bool?
}

This needs fixing or the SDK won't work

@bukira bukira changed the title CORE BUG in Decoder Broken SDK CORE BUG in Decoder Nov 18, 2024
@matthewelwell
Copy link
Contributor

Hi @bukira , I'm sorry but could you please be more descriptive here? From the description of this issue it's very hard for me to understand what the issue is.

Also, if you're willing to submit a PR, we'd gratefully receive it.

@bukira
Copy link
Author

bukira commented Nov 18, 2024

ok sorry I thought it was self explanatory with the fix posted

The SDK errors because the coding key transient is optional or null so it cannot decode it to a non null value, not sure how anyone else has ever got the SDK to work but it won decode Traits or Identity

This is the swift error

decoding(Swift.DecodingError.keyNotFound(CodingKeys(stringValue: "transient", intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: "transient", intValue: nil) ("transient").",

The fix in Traits and Identity is to change this line

public let transient: Bool

to an optional
public let transient: Bool?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants