3lvis / Networking

Swift HTTP Networking with stubbing and caching support
MIT License
1.36k stars 112 forks source link

`cacheOrPurgeData` causing production crashes #248

Closed aasatt closed 5 years ago

aasatt commented 5 years ago

The cacheOrPurgeData function is hitting a fatal error intermittently. I am unable to reproduce the issue while debugging but it is pretty clear in my crash reports.

From what I can see, it would be okay if this function fails silently.

I would like to propose that we swap the fatalError out in favor of an assert and just return inside the guard

Current:

func cacheOrPurgeData(data: Data?, path: String, cacheName: String?, cachingLevel: CachingLevel) {     
    guard let destinationURL = try? self.destinationURL(for: path, cacheName: cacheName) else {
        fatalError("Couldn't get destination URL for path: \(path) and cacheName: \(String(describing: cacheName))")
    }
    ...
}

Proposed solution:

func cacheOrPurgeData(data: Data?, path: String, cacheName: String?, cachingLevel: CachingLevel) {     
    guard let destinationURL = try? self.destinationURL(for: path, cacheName: cacheName) else {
        assertionFailure("Couldn't get destination URL for path: \(path) and cacheName: \(String(describing: cacheName))")
        return
    }
    ...
}
3lvis commented 5 years ago

Oh, we need to fix this. Any chance to get a PR @aasatt ?

3lvis commented 5 years ago

Fixed in https://github.com/3lvis/Networking/pull/249

3lvis commented 5 years ago

Released in https://github.com/3lvis/Networking/releases/tag/5.0.1