swiftlang / swiftly

A Swift toolchain installer and manager, written in Swift.
https://swiftlang.github.io/swiftly/
Apache License 2.0
490 stars 28 forks source link

`swiftly list-available` command is broken due to the addition of a platform without `archs` to https://www.swift.org/api/v1/install/releases.json #168

Closed cockscomb closed 1 month ago

cockscomb commented 1 month ago

While testing swiftly, I started getting the following error today (after the release of Swift 6.0).

$ swiftly list-available
Error: keyNotFound(CodingKeys(stringValue: "archs", intValue: nil), Swift.DecodingError.Context(codingPath: [_CodingKey(stringValue: "Index 62", intValue: 62), CodingKeys(stringValue: "platforms", intValue: nil), _CodingKey(stringValue: "Index 8", intValue: 8)], debugDescription: "No value associated with key CodingKeys(stringValue: \"archs\", intValue: nil) (\"archs\").", underlyingError: nil))

According to the error, it seems that there is an entry without archs in the API response. This appears to be caused by the following section of HTTPClient.swift.

https://github.com/swiftlang/swiftly/blob/a7ef9e838b21b7f2836f318e67b4bffa6bee259f/Sources/SwiftlyCore/HTTPClient.swift#L29-L31

Here, I checked the API response.

$ curl -s https://www.swift.org/api/v1/install/releases.json | jq '.[] | select(.name == "6.0")'
{
  "name": "6.0",
  "tag": "swift-6.0-RELEASE",
  "xcode": "Xcode 16",
  "xcode_release": true,
  "date": "2024-09-16",
  "platforms": [
    {
      "name": "Ubuntu 20.04",
      "platform": "Linux",
      "docker": "Coming Soon",
      "archs": [
        "x86_64",
        "aarch64"
      ]
    },
    {
      "name": "Ubuntu 22.04",
      "platform": "Linux",
      "docker": "Coming Soon",
      "archs": [
        "x86_64",
        "aarch64"
      ]
    },
    {
      "name": "Ubuntu 24.04",
      "platform": "Linux",
      "docker": "Coming Soon",
      "archs": [
        "x86_64",
        "aarch64"
      ]
    },
    {
      "name": "Debian 12",
      "platform": "Linux",
      "docker": "Coming Soon",
      "archs": [
        "x86_64",
        "aarch64"
      ]
    },
    {
      "name": "Fedora 39",
      "platform": "Linux",
      "docker": "Coming Soon",
      "archs": [
        "x86_64",
        "aarch64"
      ]
    },
    {
      "name": "Amazon Linux 2",
      "platform": "Linux",
      "docker": "Coming Soon",
      "archs": [
        "x86_64",
        "aarch64"
      ]
    },
    {
      "name": "Red Hat Universal Base Image 9",
      "platform": "Linux",
      "docker": "Coming Soon",
      "dir": "ubi9",
      "archs": [
        "x86_64",
        "aarch64"
      ]
    },
    {
      "name": "Windows 10",
      "platform": "Windows",
      "docker": "Coming Soon",
      "archs": [
        "x86_64",
        "arm64"
      ]
    },
    {
      "name": "Static SDK",
      "platform": "static-sdk",
      "checksum": "7984c2cf175bde52ba6ea1fcbe27fc4a148a6237c41c719209c9288ed3ceb652"
    }
  ]
}

According to this result, the Static SDK for version 6.0 does not have archs.

cockscomb commented 1 month ago

I just checked, and now the API response includes archs, so the issue has been resolved. Thank you.