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

Swift 6 Support & Sendable issue #1023

Open
nholloh opened this issue Feb 3, 2025 · 1 comment
Open

Swift 6 Support & Sendable issue #1023

nholloh opened this issue Feb 3, 2025 · 1 comment

Comments

@nholloh
Copy link

nholloh commented Feb 3, 2025

While working on !1022 I saw that the compiler currently issues a warning about the ISO8601DateFormatter used when decoding the TokenResponse, as the ISO8601DateFormatter does not conform to Sendable.

  static func parse(fromData: Data) throws -> Self {
    let decoder = Config.jsonDecoder()

    decoder.keyDecodingStrategy = .convertFromSnakeCase

    let dateFormatter = ISO8601DateFormatter()
    dateFormatter.formatOptions = [.withInternetDateTime]
    dateFormatter.timeZone = TimeZone(secondsFromGMT: 0)

    decoder.dateDecodingStrategy = .custom { decoder in
      let container = try decoder.singleValueContainer()
      let dateString = try container.decode(String.self)

      return dateFormatter.date(from: dateString) ?? Date()
    }

    var response = try decoder.decode(TokenResponse.self, from: fromData)
    response.issuedAt = response.issuedAt ?? Date()

    guard response.token != nil || response.accessToken != nil else {
      throw DecodingError.keyNotFound(CodingKeys.token, .init(codingPath: [], debugDescription: "Missing token or access_token. One must be present."))
    }

    return response
  }

Since this is an error in Swift 6, it should probably be addressed. Before doing the easy thing moving the instantiation and configuration of the ISO8601DateFormatter into the closure I wanted to understand what the reason was to choose a custom decoder over the standard .iso8601 date decoding strategy?

@edigaryev
Copy link
Collaborator

Before doing the easy thing moving the instantiation and configuration of the ISO8601DateFormatter into the closure I wanted to understand what the reason was to choose a custom decoder over the standard .iso8601 date decoding strategy?

That's because Docker Registry v2 authentication uses RFC 3339 instead of ISO 8601.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants