You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When one cancels a URLSessionDataTask before it even starts, a `URLError` is passed to the callback. The `userInfo` field is blank on Linux, in an unnecessary inconsistency.
import Dispatch
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
let session = URLSession(configuration: .default)
defer { session.finishTasksAndInvalidate() }
let s = DispatchSemaphore(value: 0)
let task = session.dataTask(with: URL(string: "https://www.swift.org")!) {
(_, _, error) in
let e = error as! URLError
let i = e.userInfo
i.keys.sorted().forEach { print("\($0): \(i[$0]!)") }
print("\(i.count) key-value pair\(i.count == 1 ? "" : "s")")
s.signal()
}
task.cancel()
s.wait()
On macOS:
$ swift --version && swift urlsessiontask-cancellation.swift
Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)
Target: x86_64-apple-darwin19.5.0
NSErrorFailingURLKey: https://www.swift.org
NSErrorFailingURLStringKey: https://www.swift.org
NSLocalizedDescription: cancelled
3 key-value pairs
On Linux:
$ swift --version && swift urlsessiontask-cancellation.swift
Swift version 5.2.4 (swift-5.2.4-RELEASE)
Target: x86_64-unknown-linux-gnu
0 key-value pairs
The text was updated successfully, but these errors were encountered:
swift-corelibs-foundation is generally inconsistent about how it builds its URLError instances. Some include the URL, some also include NSLocalizedDescription, some include nothing. As a result, user code cannot rely on them for context.
Attachment: Download
Environment
Swift 5.2.4 on macOS (Xcode 11.5/macOS 10.15) and Linux (ubuntu 18.04)
Additional Detail from JIRA
md5: d1ad5b8e981926caf0d4c6c32f6eebdf
Issue Description:
When one cancels a URLSessionDataTask before it even starts, a `URLError` is passed to the callback. The `userInfo` field is blank on Linux, in an unnecessary inconsistency.
On macOS:
On Linux:
The text was updated successfully, but these errors were encountered: