Merge pull request #2074 from jcanizales/fix-metadata-usage-in-example
Fix NPE for trying to add metadata to error when it was nil
diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m
index 279ef93..d92a9d1 100644
--- a/src/objective-c/GRPCClient/GRPCCall.m
+++ b/src/objective-c/GRPCClient/GRPCCall.m
@@ -319,9 +319,12 @@
if (strongSelf) {
[strongSelf->_responseMetadata addEntriesFromDictionary:trailers];
- NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:error.userInfo];
- userInfo[kGRPCStatusMetadataKey] = strongSelf->_responseMetadata;
- error = [NSError errorWithDomain:error.domain code:error.code userInfo:userInfo];
+ if (error) {
+ NSMutableDictionary *userInfo =
+ [NSMutableDictionary dictionaryWithDictionary:error.userInfo];
+ userInfo[kGRPCStatusMetadataKey] = strongSelf->_responseMetadata;
+ error = [NSError errorWithDomain:error.domain code:error.code userInfo:userInfo];
+ }
[strongSelf finishWithError:error];
}
}];