SwiftPackageIndex / SwiftPackageIndex-Server

The Swift Package Index is the place to find Swift packages!
https://swiftpackageindex.com
Apache License 2.0
554 stars 45 forks source link

Nightly fails for mustiikhalil/flatbuffers #848

Closed finestructure closed 3 years ago

finestructure commented 3 years ago
Dependencies for https://github.com/mustiikhalil/flatbuffers.git ...
ERROR: Error Domain=NSCocoaErrorDomain Code=256 "The file “Package.swift” couldn’t be opened." UserInfo={NSURL=https://raw.githubusercontent.com/mustiikhalil/flatbuffers/master/Package.swift}

Default branch is swift, which has a Package.swift file. There's also a master branch without one. Perhaps we're using the wrong branch.

finestructure commented 3 years ago

Well, this is weird, but it explains why we're looking for the manifest file in the master branch:

❯ curl -s https://api.github.com/repos/mustiikhalil/flatbuffers | grep default_branch
  "default_branch": "master",
    "default_branch": "master"
    "default_branch": "master"
finestructure commented 3 years ago

Whereas the GraphQL query returns

{
  "data": {
    "repository": {
      "defaultBranchRef": {
        "name": "swift"
      }
    }
  }
}

which explains why we handle it correctly in the server.

Sherlouk commented 3 years ago

What on actual earth 😂

I wonder if it's a bug to do with it being a fork? Since the fork's parent's default branch actually is master... but there is a separate field for that so it should be capable of telling us.

finestructure commented 3 years ago

Making progress - we're now failing with a missing repository and I think the issue is that previously this was a 404 from the REST API request whereas now it's in the response:

ERROR: decodingError(context: "https://api.github.com/graphql", underlyingError: Swift.DecodingError.valueNotFound(Swift.KeyedDecodingContainer<ValidatorCore.Github.Repository.(unknown context at $1024f6d60).CodingKeys>, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "data", intValue: nil), CodingKeys(stringValue: "repository", intValue: nil)], debugDescription: "Cannot get keyed decoding container -- found null value instead.", underlyingError: nil)), json: "{\"data\":{\"repository\":null},\"errors\":[{\"type\":\"NOT_FOUND\",\"path\":[\"repository\"],\"locations\":[{\"line\":2,\"column\":3}],\"message\":\"Could not resolve to a Repository with the name \'stephencelis/SQLite\'.\"}]}")

There's an XKCD in here about wrapping a 404 in a 200 with an error wrapped in JSON.

Ah, progress.

finestructure commented 3 years ago

Ah yes, of course...


ERROR: decodingError(context: "https://api.github.com/graphql", underlyingError: Swift.DecodingError.keyNotFound(CodingKeys(stringValue: "data", intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: \"data\", intValue: nil) (\"data\").", underlyingError: nil)), json: "{\"errors\":[{\"type\":\"RATE_LIMITED\",\"message\":\"API rate limit exceeded\"}]}")
finestructure commented 3 years ago

Ok, this is bad. It looks like the rate limit is only transmitted in the JSON response and it doesn't include any rate limit details:

            {
                "errors": [
                    {
                        "type": "RATE_LIMITED",
                        "message": "API rate limit exceeded"
                    }
                ]
            }

which means we can't extract the reset time and wait:

let remaining = response.headers.first(name: "X-RateLimit-Remaining")
                .flatMap(Int.init),
let reset = response.headers.first(name: "X-RateLimit-Reset")
                .flatMap(TimeInterval.init)
                .flatMap(Date.init(timeIntervalSince1970:))

like we currently do.

I'm tempted to roll all of this back and stick with the REST API calls. It's going to be a huge hassle to change everything to start polling the API until the rate limit resets. (Leaving aside that this polling itself risks the node earning an IP ban on top of the normal rate limit.)

After all, the reason I made this change was to work around what looked like a bug in the API for a single fork reporting a wrong default branch. We can simply handle that error more gracefully and skip that repository.

daveverwer commented 3 years ago

Yea that's not good.

I know it's layering on more complexity, but would it be worth pinging the REST API for a rate limit check when the GQL one starts returning this error. Complex and ugly though.

finestructure commented 3 years ago

Yeah, that would work but I don't think we want that additional complexity. It's messy even as it is and I shouldn't have added that QGL query without stepping back and looking at the wider issue.

Because what's actually happening is that that package we salvage in one step where we recover the manifest, we then throw it out in the next step because it's a fork!

And like James, I suspect the fork is the issue.

Either way, I'd much rather let the nightly perhaps fail to discover the odd dependency that can always be properly added to SPI than maintain this... In particular because we're likely/hopefully touching this rarely it's better if it's simpler.

Does that make sense?

finestructure commented 3 years ago

Well and today it's fixed 🤣

❯ curl -s https://api.github.com/repos/mustiikhalil/flatbuffers | grep default_branch
  "default_branch": "swift",
    "default_branch": "master"
    "default_branch": "master"

(It's the first one we're decoding)

finestructure commented 3 years ago

Progress:

2020-12-09T12:23:05.6180830Z Dependencies for https://github.com/Mieraidihaimu/MMFoundation_swift.git ...
2020-12-09T12:23:05.6182620Z ERROR: repositoryNotFound(owner: "Mieraidihaimu", name: "MMFoundation_swift")
2020-12-09T12:23:05.6183280Z Retrying in 5 seconds ...
2020-12-09T12:23:05.6183720Z Finding dependencies (attempt 2)
2020-12-09T12:23:05.6184440Z Dependencies for https://github.com/Mieraidihaimu/MMFoundation_swift.git ...
2020-12-09T12:23:05.6185330Z ERROR: repositoryNotFound(owner: "Mieraidihaimu", name: "MMFoundation_swift")
2020-12-09T12:23:05.6185940Z Retrying in 10 seconds ...
2020-12-09T12:23:05.6186370Z Finding dependencies (attempt 3)
2020-12-09T12:23:05.6187090Z Dependencies for https://github.com/Mieraidihaimu/MMFoundation_swift.git ...
2020-12-09T12:23:05.6187970Z ERROR: repositoryNotFound(owner: "Mieraidihaimu", name: "MMFoundation_swift")
2020-12-09T12:23:05.6188580Z Retrying in 20 seconds ...
2020-12-09T12:23:05.6298750Z ##[error]Process completed with exit code 1.

https://pipelines.actions.githubusercontent.com/BHXUDvWH6EZe7UmPjdxQbFvy6ORMllgvsUyJQIo12NY4eEmiDl/_apis/pipelines/1/runs/1378/signedlogcontent/3?urlExpires=2020-12-09T13%3A30%3A45.0899846Z&urlSigningMethod=HMACV1&urlSignature=hZZr%2FmNmw8Rgds4sEnkrBtjUFbruUjj6b4ebltgbOTw%3D