AliSoftware / OHHTTPStubs

Stub your network requests easily! Test your apps with fake network data and custom response time, response code and headers!
MIT License
5.03k stars 601 forks source link

Better nullability and error handling #315

Open ZevEisenberg opened 4 years ago

ZevEisenberg commented 4 years ago

Checklist

Description

Fixes #290

Also does more idiomatic error handling:

Wrong:

NSError *error;
NSArray *result = [someObject someMethod error:&error];
if (!error) {
    // assume success
}

Correct:

NSError *error;
NSArray *result = [someObject someMethod error:&error];
if (result) {
    // assume success
}

Motivation and Context

The main motivation was addressing static analysis warnings I encountered when analyzing an Objective-C project. The error handling was just something I fixed along the way.

Note: I also added a couple of missing generics annotations which may affect the public interface. If they are imported into Swift, they will go from [Any] to [OHHTTPStubsDescriptor]. ~This is a breaking change for anyone who is using the output of this method in Swift.~ Actually, it may not be breaking, since in Swift, they were probably already doing something like for descriptor in descriptors as! [OHHTTPStubsDescriptor], and after this update, that line will throw a compile warning, not an error. So this can probably be a bugfix, not a major release.

Testing: I added a couple of missing tests for error throwing cases, and made sure all the tests were passing.