onevcat / Kingfisher

A lightweight, pure-Swift library for downloading and caching images from the web.
MIT License
23.4k stars 2.66k forks source link

Using cancelDownloadTask prints errors to the console #1068

Closed elveatles closed 5 years ago

elveatles commented 5 years ago

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

Issue Description

Downloading images for UITableViewCells and cancelling them spams the console with error logs explaining that download tasks were cancelled even though the cancellation was intentional. Everything works as expected though. It's just the console logs that are unwanted.

What

I'm using Kinfisher to download images for UITableViewCells. I'm using cell.imageView.kf.cancelDownloadTask() in

func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath)

to cancel image downloads for cells that are offscreen. I keep getting errors printed to the console like:

2018-12-12 16:25:16.416483-0800 MovieNight[50080:2180568] Task <25AB98C1-CD14-4BA8-9546-DF6E9D34BD05>.<10> load failed with error Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLStringKey=https://image.tmdb.org/t/p/w45/2vrnA7cg6D7EmOlwivGsuHnk2f9.jpg, NSErrorFailingURLKey=https://image.tmdb.org/t/p/w45/2vrnA7cg6D7EmOlwivGsuHnk2f9.jpg, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <25AB98C1-CD14-4BA8-9546-DF6E9D34BD05>.<10>" ), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <25AB98C1-CD14-4BA8-9546-DF6E9D34BD05>.<10>, NSLocalizedDescription=cancelled} [-999]

Despite this, everything seems to be working as intended. The images are being downloaded and caching just fine. It's just annoying and alarming to see these error messages in the console when I intended to cancel the downloads.

Reproduce

In func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell.

let url = URL("https://image.tmdb.org/t/p/w45/2vrnA7cg6D7EmOlwivGsuHnk2f9.jpg")!
cell.imageView?.kf.setImage(with: url)
cell.imageView?.kf.cancelDownloadTask()

Other Comment

If the cancelDownloadTask line is commented out, you won't see errors printed to the console.

This will only happen if the images are not already cached.

Using version 5.0.0

onevcat commented 5 years ago

This log comes out from NSURLSession when an on-going task is canceled. Since it is a behavior in Foundation framework, I guess there is little Kingfisher could do.

Maybe there would be some log options in Xcode could suppress this log. But now I don't have any information on it. You can also try to ask on StackOverflow or file a radar to Apple.

elveatles commented 5 years ago

Thank you for the quick reply. What a bummer that it's coming from Foundation code. I'll see what I can get out of StackOverflow or Apple.