Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ extension Queries {
func dictionaryReducer(container: KeyedDecodingContainer<Queries.IDCodingKey>, category: String) -> ([String: ResultComponent], Queries.IDCodingKey) throws -> [String: ResultComponent] {
return { (dict, id) -> [String: ResultComponent] in
var dict = dict
if let entry = try? container.decode(ResultEntry.self, forKey: id) {
dict[id.stringValue] = entry
} else if let error = try? container.decode(ResultError.self, forKey: id) {
if let error = try? container.decode(ResultError.self, forKey: id) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for error results first.

The package-version api could in the past return 'error' values alongside 'kmp' and 'version' properties for some scenarios, e.g. https://api.keyman.com/package-version?platform=ioskeyboard=enhlao:

{
    "keyboards": {
        "enhlao": {
            "version": "1.1",
            "error": "not available for platform",
            "kmp": "https://keyman.com/go/package/download/keyboard/enhlao?version=1.1&update=1"
        }
    }
}

Note that after keymanapp/api.keyman.com#325 merges, it will instead return:

{
    "keyboards": {
        "enhlao": {
            "error": "Not available for platform ios"
        }
    }
}

This was unlikely to ever have arisen in the past because the only errors this could happen for were 'not available for platform' or 'not available as package', and it's hard to see how someone could have installed the keyboard in the first place in that scenario!

But that changes once we have min version checking in place. Consistency in the api response and the processing is neat and tidy, even though fixing just at one end would be sufficient to address the problem.

dict[id.stringValue] = error
} else if let entry = try? container.decode(ResultEntry.self, forKey: id) {
dict[id.stringValue] = entry
} else {
throw FetchError.decodingError(category, id.stringValue)
}
Expand Down Expand Up @@ -116,7 +116,10 @@ extension Queries {
return URLQueryItem(name: resourceField, value: key.id)
}

urlComponents.queryItems = queryItems + [URLQueryItem(name: "platform", value: "ios")]
urlComponents.queryItems = queryItems + [
URLQueryItem(name: "platform", value: "ios"),
URLQueryItem(name: "keyman-version", value: Version.current.plainString)
]
let message = "Querying package versions through API endpoint: \(urlComponents.url!)"
os_log("%{public}s", log:KeymanEngineLogger.resources, type: .info, message)
SentryManager.breadcrumb(message)
Expand Down