Permalink
Browse files

Error passing now *finally* works properly.

When creating an invocation, we have to create and assign both an NSError and a pointer to that NSError. We then send the address of the pointer to the error to the invocation by reference. Phew.
(Also we now return after we call our failureBlock, otherwise we'll call the successBlock afterwards. And that ain't right.)
  • Loading branch information...
Owain R Hunt
Owain R Hunt committed May 7, 2012
1 parent cfbfc19 commit 16097bcce5cbaf8414cacf1538947d054826627b
Showing with 52 additions and 27 deletions.
  1. +25 −15 UAGithubEngine.xcodeproj/project.pbxproj
  2. +27 −12 UAGithubEngine/UAGithubEngine.m
@@ -130,6 +130,27 @@
CC52FFA115378566005A767A /* UAGithubEngine */ = {
isa = PBXGroup;
children = (
+ CC52FFB8153785F3005A767A /* UAGithubEngine.h */,
+ CC73E2151551DA590094AFE6 /* Engine */,
+ CC52FFA215378566005A767A /* Supporting Files */,
+ );
+ path = UAGithubEngine;
+ sourceTree = "<group>";
+ };
+ CC52FFA215378566005A767A /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ CC52FFA315378566005A767A /* UAGithubEngine-Info.plist */,
+ CC52FFA415378566005A767A /* InfoPlist.strings */,
+ CC52FFA715378566005A767A /* UAGithubEngine-Prefix.pch */,
+ );
+ name = "Supporting Files";
+ sourceTree = "<group>";
+ };
+ CC73E2151551DA590094AFE6 /* Engine */ = {
+ isa = PBXGroup;
+ children = (
+ CC52FFB9153785F3005A767A /* UAGithubEngine.m */,
CC52FFAE153785F3005A767A /* NSArray+Utilities.h */,
CC52FFAF153785F3005A767A /* NSArray+Utilities.m */,
CC52FFB0153785F3005A767A /* NSData+Base64.h */,
@@ -140,8 +161,6 @@
CC52FFB5153785F3005A767A /* NSString+UAGithubEngineUtilities.m */,
CC52FFB6153785F3005A767A /* NSString+UUID.h */,
CC52FFB7153785F3005A767A /* NSString+UUID.m */,
- CC52FFB8153785F3005A767A /* UAGithubEngine.h */,
- CC52FFB9153785F3005A767A /* UAGithubEngine.m */,
CC52FFBA153785F3005A767A /* UAGithubEngineConstants.h */,
CC52FFBB153785F3005A767A /* UAGithubEngineConstants.m */,
CC52FFBC153785F3005A767A /* UAGithubEngineRequestTypes.h */,
@@ -151,19 +170,8 @@
CC52FFC0153785F3005A767A /* UAGithubURLConnection.m */,
CC52FFC1153785F3005A767A /* UAReachability.h */,
CC52FFC2153785F3005A767A /* UAReachability.m */,
- CC52FFA215378566005A767A /* Supporting Files */,
- );
- path = UAGithubEngine;
- sourceTree = "<group>";
- };
- CC52FFA215378566005A767A /* Supporting Files */ = {
- isa = PBXGroup;
- children = (
- CC52FFA315378566005A767A /* UAGithubEngine-Info.plist */,
- CC52FFA415378566005A767A /* InfoPlist.strings */,
- CC52FFA715378566005A767A /* UAGithubEngine-Prefix.pch */,
);
- name = "Supporting Files";
+ name = Engine;
sourceTree = "<group>";
};
/* End PBXGroup section */
@@ -214,7 +222,7 @@
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 0430;
+ LastUpgradeCheck = 0440;
};
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "UAGithubEngine" */;
compatibilityVersion = "Xcode 3.2";
@@ -280,6 +288,7 @@
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
+ COMBINE_HIDPI_IMAGES = YES;
GCC_C_LANGUAGE_STANDARD = "compiler-default";
GCC_OPTIMIZATION_LEVEL = 0;
GCC_VERSION = 4.2;
@@ -296,6 +305,7 @@
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
+ COMBINE_HIDPI_IMAGES = YES;
GCC_C_LANGUAGE_STANDARD = "compiler-default";
GCC_VERSION = 4.2;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
@@ -86,7 +86,7 @@ - (UAReachability *)reachability
#pragma mark Request Management
#pragma mark
-- (id)sendRequest:(NSString *)path requestType:(UAGithubRequestType)requestType responseType:(UAGithubResponseType)responseType withParameters:(id)params page:(NSInteger)page error:(NSError **)error
+- (id)sendRequest:(NSString *)path requestType:(UAGithubRequestType)requestType responseType:(UAGithubResponseType)responseType withParameters:(id)params page:(NSInteger)page error:(NSError * __strong *)error
{
NSMutableString *urlString = [NSMutableString stringWithFormat:@"%@%@/%@", API_PROTOCOL, API_DOMAIN, path];
@@ -238,7 +238,8 @@ - (id)sendRequest:(NSString *)path requestType:(UAGithubRequestType)requestType
break;
}
- __block NSError *blockError = nil;
+ NSError __block __strong *blockError = nil;
+ NSError *connectionError = nil;
id returnValue = [UAGithubURLConnection asyncRequest:urlRequest
success:^(NSData *data, NSURLResponse *response)
@@ -250,7 +251,7 @@ - (id)sendRequest:(NSString *)path requestType:(UAGithubRequestType)requestType
if ([[[resp allHeaderFields] allKeys] containsObject:@"X-Ratelimit-Remaining"] && [[[resp allHeaderFields] valueForKey:@"X-Ratelimit-Remaining"] isEqualToString:@"1"])
{
blockError = [NSError errorWithDomain:UAGithubAPILimitReached code:statusCode userInfo:[NSDictionary dictionaryWithObject:urlRequest forKey:@"request"]];
- return [NSError errorWithDomain:UAGithubAPILimitReached code:statusCode userInfo:[NSDictionary dictionaryWithObject:urlRequest forKey:@"request"]];
+ return (id)[NSNull null];
}
if (statusCode >= 400)
@@ -273,7 +274,9 @@ - (id)sendRequest:(NSString *)path requestType:(UAGithubRequestType)requestType
}
}
- return [NSError errorWithDomain:@"HTTP" code:statusCode userInfo:[NSDictionary dictionaryWithObject:urlRequest forKey:@"request"]];
+ blockError = [NSError errorWithDomain:@"HTTP" code:statusCode userInfo:[NSDictionary dictionaryWithObject:urlRequest forKey:@"request"]];
+
+ return (id)[NSNull null];
}
@@ -288,13 +291,18 @@ - (id)sendRequest:(NSString *)path requestType:(UAGithubRequestType)requestType
}
}
- error:&blockError];
+ error:&connectionError];
if (blockError)
{
*error = blockError;
return nil;
}
+ else if (connectionError)
+ {
+ *error = connectionError;
+ return nil;
+ }
// If returnValue is of class NSArray, it contains an array of NSDictionary objects.
// If it's an NSNumber YES, then we're looking at a successful call that expects a No Content response.
@@ -324,34 +332,41 @@ - (id)sendRequest:(NSString *)path requestType:(UAGithubRequestType)requestType
- (void)invoke:(void (^)(id obj))invocationBlock success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock
{
- __unsafe_unretained NSError *error = nil;
- __unsafe_unretained id result;
-
+ NSError __unsafe_unretained *error = nil;
+ NSError __unsafe_unretained **errorPointer = &error;
+ id __unsafe_unretained result;
+
NSInvocation *invocation = [NSInvocation jr_invocationWithTarget:self block:invocationBlock];
- [invocation setArgument:&error atIndex:5];
+ [invocation setArgument:&errorPointer atIndex:5];
[invocation invoke];
[invocation getReturnValue:&result];
+
if (error)
{
failureBlock(error);
+ return;
}
-
+
successBlock(result);
}
- (void)invoke:(void (^)(id obj))invocationBlock booleanSuccess:(UAGithubEngineBooleanSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock
{
- __unsafe_unretained NSError *error = nil;
+
+ NSError __unsafe_unretained *error = nil;
+ NSError __unsafe_unretained **errorPointer = &error;
BOOL result;
NSInvocation *invocation = [NSInvocation jr_invocationWithTarget:self block:invocationBlock];
- [invocation setArgument:&error atIndex:5];
+ [invocation setArgument:&errorPointer atIndex:5];
[invocation invoke];
[invocation getReturnValue:&result];
+
if (error)
{
failureBlock(error);
+ return;
}
successBlock(result);

0 comments on commit 16097bc

Please sign in to comment.