Skip to content

Commit

Permalink
Functions and Storage deprecated Error variables (#9569)
Browse files Browse the repository at this point in the history
* Functions and Storage deprecated Error variables

* Test build fixes

* one more test build issue

* Review

* style
  • Loading branch information
paulb777 authored Apr 6, 2022
1 parent 3837b3e commit 111d8d6
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 27 deletions.
4 changes: 4 additions & 0 deletions FirebaseFunctions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v8.15.0
- [deprecated] The global variables `FIRFunctionsErrorDomain` and `FIRFunctionsErrorDetailsKey` are
deprecated and will be removed in v9.0.0. (#9569)

# v8.9.0
- [fixed] Add watchOS support for Swift Package Manager (#8864).

Expand Down
6 changes: 6 additions & 0 deletions FirebaseFunctions/Sources/FIRFunctions+Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,10 @@ NS_ASSUME_NONNULL_BEGIN

@end

// The error domain for codes in the FIRFunctionsErrorCode enum.
FOUNDATION_EXPORT NSString *const FIRFunctionsErrorDomainInternal;

// The key for finding error details in the NSError userInfo.
FOUNDATION_EXPORT NSString *const FIRFunctionsErrorDetailsKeyInternal;

NS_ASSUME_NONNULL_END
4 changes: 2 additions & 2 deletions FirebaseFunctions/Sources/FIRFunctions.m
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ - (void)callFunction:(NSString *)name
}
if (![responseJSON isKindOfClass:[NSDictionary class]]) {
NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"Response was not a dictionary."};
error = [NSError errorWithDomain:FIRFunctionsErrorDomain
error = [NSError errorWithDomain:FIRFunctionsErrorDomainInternal
code:FIRFunctionsErrorCodeInternal
userInfo:userInfo];
if (completion) {
Expand All @@ -311,7 +311,7 @@ - (void)callFunction:(NSString *)name
}
if (!dataJSON) {
NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"Response is missing data field."};
error = [NSError errorWithDomain:FIRFunctionsErrorDomain
error = [NSError errorWithDomain:FIRFunctionsErrorDomainInternal
code:FIRFunctionsErrorCodeInternal
userInfo:userInfo];
if (completion) {
Expand Down
8 changes: 5 additions & 3 deletions FirebaseFunctions/Sources/FUNError.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
NS_ASSUME_NONNULL_BEGIN

NSString *const FIRFunctionsErrorDomain = @"com.firebase.functions";
NSString *const FIRFunctionsErrorDomainInternal = @"com.firebase.functions";
NSString *const FIRFunctionsErrorDetailsKey = @"details";
NSString *const FIRFunctionsErrorDetailsKeyInternal = @"details";

/**
* Takes an HTTP status code and returns the corresponding FIRFunctionsErrorCode error code.
Expand Down Expand Up @@ -138,7 +140,7 @@ FIRFunctionsErrorCode FIRFunctionsErrorCodeForHTTPStatus(NSInteger status) {

NSError *_Nullable FUNErrorForCode(FIRFunctionsErrorCode code) {
NSDictionary *userInfo = @{NSLocalizedDescriptionKey : FUNDescriptionForErrorCode(code)};
return [NSError errorWithDomain:FIRFunctionsErrorDomain code:code userInfo:userInfo];
return [NSError errorWithDomain:FIRFunctionsErrorDomainInternal code:code userInfo:userInfo];
}

NSError *_Nullable FUNErrorForResponse(NSInteger status,
Expand Down Expand Up @@ -188,9 +190,9 @@ FIRFunctionsErrorCode FIRFunctionsErrorCodeForHTTPStatus(NSInteger status) {
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
userInfo[NSLocalizedDescriptionKey] = description;
if (details) {
userInfo[FIRFunctionsErrorDetailsKey] = details;
userInfo[FIRFunctionsErrorDetailsKeyInternal] = details;
}
return [NSError errorWithDomain:FIRFunctionsErrorDomain code:code userInfo:userInfo];
return [NSError errorWithDomain:FIRFunctionsErrorDomainInternal code:code userInfo:userInfo];
}

NS_ASSUME_NONNULL_END
3 changes: 2 additions & 1 deletion FirebaseFunctions/Sources/FUNSerializer.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#import "FirebaseFunctions/Sources/FUNSerializer.h"

#import "FirebaseFunctions/Sources/FIRFunctions+Internal.h"
#import "FirebaseFunctions/Sources/FUNUsageValidation.h"
#import "FirebaseFunctions/Sources/Public/FirebaseFunctions/FIRError.h"

Expand Down Expand Up @@ -137,7 +138,7 @@ - (id)encode:(id)object {
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey : description,
};
return [NSError errorWithDomain:FIRFunctionsErrorDomain
return [NSError errorWithDomain:FIRFunctionsErrorDomainInternal
code:FIRFunctionsErrorCodeInternal
userInfo:userInfo];
}
Expand Down
10 changes: 7 additions & 3 deletions FirebaseFunctions/Sources/Public/FirebaseFunctions/FIRError.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
NS_ASSUME_NONNULL_BEGIN

// The error domain for codes in the FIRFunctionsErrorCode enum.
FOUNDATION_EXPORT NSString *const FIRFunctionsErrorDomain NS_SWIFT_NAME(FunctionsErrorDomain);
FOUNDATION_EXPORT NSString *const FIRFunctionsErrorDomain NS_SWIFT_NAME(FunctionsErrorDomain)
DEPRECATED_MSG_ATTRIBUTE("The variable will be unavailable in a future release,"
" but the string will not change.");

// The key for finding error details in the NSError userInfo.
// clang-format off
// clang-format12 merges the next two lines.
// clang-format14 merges the next two lines.
FOUNDATION_EXPORT NSString *const FIRFunctionsErrorDetailsKey
NS_SWIFT_NAME(FunctionsErrorDetailsKey);
NS_SWIFT_NAME(FunctionsErrorDetailsKey)
DEPRECATED_MSG_ATTRIBUTE("The variable will be unavailable from Objective C in a future release,"
" but the string will not change.");
// clang-format on

/**
Expand Down
4 changes: 2 additions & 2 deletions FirebaseFunctions/Tests/Integration/FIRIntegrationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ - (void)testExplicitError {
XCTAssertEqual(FIRFunctionsErrorCodeOutOfRange, error.code);
XCTAssertEqualObjects(@"explicit nope", error.userInfo[NSLocalizedDescriptionKey]);
NSDictionary *expectedDetails = @{@"start" : @10, @"end" : @20, @"long" : @30L};
XCTAssertEqualObjects(expectedDetails, error.userInfo[FIRFunctionsErrorDetailsKey]);
XCTAssertEqualObjects(expectedDetails, error.userInfo[@"details"]);
[expectation fulfill];
}];
[self waitForExpectations:@[ expectation ] timeout:10];
Expand All @@ -235,7 +235,7 @@ - (void)testTimeout {
XCTAssertNotNil(error);
XCTAssertEqual(FIRFunctionsErrorCodeDeadlineExceeded, error.code);
XCTAssertEqualObjects(@"DEADLINE EXCEEDED", error.userInfo[NSLocalizedDescriptionKey]);
XCTAssertNil(error.userInfo[FIRFunctionsErrorDetailsKey]);
XCTAssertNil(error.userInfo[@"details"]);
[expectation fulfill];
}];
[self waitForExpectations:@[ expectation ] timeout:10];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class IntegrationTests: XCTestCase {
XCTAssertEqual(FunctionsErrorCode.outOfRange.rawValue, error.code)
XCTAssertEqual("explicit nope", error.localizedDescription)
XCTAssertEqual(["start": 10 as Int32, "end": 20 as Int32, "long": 30],
error.userInfo[FunctionsErrorDetailsKey] as! [String: Int32])
error.userInfo["details"] as! [String: Int32])
expectation.fulfill()
} catch {
XCTAssert(false, "Failed to unwrap the function result: \(error)")
Expand All @@ -399,7 +399,7 @@ class IntegrationTests: XCTestCase {
XCTAssertEqual(FunctionsErrorCode.outOfRange.rawValue, error.code)
XCTAssertEqual("explicit nope", error.localizedDescription)
XCTAssertEqual(["start": 10 as Int32, "end": 20 as Int32, "long": 30],
error.userInfo[FunctionsErrorDetailsKey] as! [String: Int32])
error.userInfo["details"] as! [String: Int32])
return
}
XCTAssertFalse(true, "Failed to throw error for missing result")
Expand Down Expand Up @@ -451,7 +451,7 @@ class IntegrationTests: XCTestCase {
let error = try XCTUnwrap(error! as NSError)
XCTAssertEqual(FunctionsErrorCode.deadlineExceeded.rawValue, error.code)
XCTAssertEqual("DEADLINE EXCEEDED", error.localizedDescription)
XCTAssertNil(error.userInfo[FunctionsErrorDetailsKey])
XCTAssertNil(error.userInfo["details"])
expectation.fulfill()
} catch {
XCTAssert(false, "Failed to unwrap the function result: \(error)")
Expand All @@ -473,7 +473,7 @@ class IntegrationTests: XCTestCase {
let error = try XCTUnwrap(error) as NSError
XCTAssertEqual(FunctionsErrorCode.deadlineExceeded.rawValue, error.code)
XCTAssertEqual("DEADLINE EXCEEDED", error.localizedDescription)
XCTAssertNil(error.userInfo[FunctionsErrorDetailsKey])
XCTAssertNil(error.userInfo["details"])
return
}
XCTAssertFalse(true, "Failed to throw error for missing result")
Expand Down
2 changes: 1 addition & 1 deletion FirebaseFunctions/Tests/Unit/FUNSerializerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ - (void)testDecodeInvalidLong {
NSNumber *actual = [serializer decode:input error:&error];
XCTAssertNil(actual);
XCTAssertNotNil(error);
XCTAssertEqualObjects(FIRFunctionsErrorDomain, error.domain);
XCTAssertEqualObjects(@"com.firebase.functions", error.domain);
XCTAssertEqual(FIRFunctionsErrorCodeInternal, error.code);
}

Expand Down
8 changes: 4 additions & 4 deletions FirebaseFunctionsSwift/Tests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ class IntegrationTests: XCTestCase {
XCTAssertEqual(FunctionsErrorCode.outOfRange.rawValue, error.code)
XCTAssertEqual("explicit nope", error.localizedDescription)
XCTAssertEqual(["start": 10 as Int32, "end": 20 as Int32, "long": 30],
error.userInfo[FunctionsErrorDetailsKey] as! [String: Int32])
error.userInfo["details"] as! [String: Int32])
expectation.fulfill()
return
}
Expand All @@ -454,7 +454,7 @@ class IntegrationTests: XCTestCase {
XCTAssertEqual(FunctionsErrorCode.outOfRange.rawValue, error.code)
XCTAssertEqual("explicit nope", error.localizedDescription)
XCTAssertEqual(["start": 10 as Int32, "end": 20 as Int32, "long": 30],
error.userInfo[FunctionsErrorDetailsKey] as! [String: Int32])
error.userInfo["details"] as! [String: Int32])
}
}
#endif
Expand Down Expand Up @@ -514,7 +514,7 @@ class IntegrationTests: XCTestCase {
let error = error as NSError
XCTAssertEqual(FunctionsErrorCode.deadlineExceeded.rawValue, error.code)
XCTAssertEqual("DEADLINE EXCEEDED", error.localizedDescription)
XCTAssertNil(error.userInfo[FunctionsErrorDetailsKey])
XCTAssertNil(error.userInfo["details"])
expectation.fulfill()
return
}
Expand All @@ -539,7 +539,7 @@ class IntegrationTests: XCTestCase {
let error = error as NSError
XCTAssertEqual(FunctionsErrorCode.deadlineExceeded.rawValue, error.code)
XCTAssertEqual("DEADLINE EXCEEDED", error.localizedDescription)
XCTAssertNil(error.userInfo[FunctionsErrorDetailsKey])
XCTAssertNil(error.userInfo["details"])
}
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions FirebaseStorage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 8.15.0
- [deprecated] The global variable `FIRStorageErrorDomain` is deprecated and will
be removed in a future release (#9569).

# 8.5.0
- [fixed] Fixed an issue where Storage could not connect to local emulators using
http (#8389).
Expand Down
1 change: 1 addition & 0 deletions FirebaseStorage/Sources/FIRStorageConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
NSString *const kFIRStorageResponseBody = @"ResponseBody";

NSString *const FIRStorageErrorDomain = @"FIRStorageErrorDomain";
NSString *const FIRStorageErrorDomainInternal = @"FIRStorageErrorDomain";

NSString *const kFIRStorageInvalidDataFormat = @"Invalid data returned from the server: %@";
NSString *const kFIRStorageInvalidObserverStatus =
Expand Down
2 changes: 2 additions & 0 deletions FirebaseStorage/Sources/FIRStorageErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ NS_ASSUME_NONNULL_BEGIN

@end

FOUNDATION_EXPORT NSString *const FIRStorageErrorDomainInternal;

NS_ASSUME_NONNULL_END
6 changes: 4 additions & 2 deletions FirebaseStorage/Sources/FIRStorageErrors.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ + (NSError *)errorWithCode:(FIRStorageErrorCode)code

errorDictionary[NSLocalizedDescriptionKey] = errorMessage;

NSError *err = [NSError errorWithDomain:FIRStorageErrorDomain code:code userInfo:errorDictionary];
NSError *err = [NSError errorWithDomain:FIRStorageErrorDomainInternal
code:code
userInfo:errorDictionary];
return err;
}

Expand Down Expand Up @@ -182,7 +184,7 @@ + (NSError *)errorWithInvalidRequest:(NSData *)request {
}

+ (NSError *)errorWithCustomMessage:(NSString *)errorMessage {
return [NSError errorWithDomain:FIRStorageErrorDomain
return [NSError errorWithDomain:FIRStorageErrorDomainInternal
code:FIRStorageErrorCodeUnknown
userInfo:@{NSLocalizedDescriptionKey : errorMessage}];
}
Expand Down
2 changes: 1 addition & 1 deletion FirebaseStorage/Sources/FIRStorageUploadTask.m
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ - (BOOL)isContentToUploadValid:(NSError **)outError {
userInfo[NSUnderlyingErrorKey] = fileReachabilityError;
}

*outError = [NSError errorWithDomain:FIRStorageErrorDomain
*outError = [NSError errorWithDomain:FIRStorageErrorDomainInternal
code:FIRStorageErrorCodeUnknown
userInfo:userInfo];
}
Expand Down
2 changes: 1 addition & 1 deletion FirebaseStorage/Sources/FIRStorageUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ + (NSString *)encodedURLForPath:(FIRStoragePath *)path {
}

+ (NSError *)storageErrorWithDescription:(NSString *)description code:(NSInteger)code {
return [NSError errorWithDomain:FIRStorageErrorDomain
return [NSError errorWithDomain:FIRStorageErrorDomainInternal
code:code
userInfo:@{NSLocalizedDescriptionKey : description}];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ typedef NS_ENUM(NSInteger, FIRStorageTaskStatus) {
/**
* Firebase Storage error domain.
*/
FOUNDATION_EXPORT NSString *const FIRStorageErrorDomain NS_SWIFT_NAME(StorageErrorDomain);
FOUNDATION_EXPORT NSString *const FIRStorageErrorDomain NS_SWIFT_NAME(StorageErrorDomain)
DEPRECATED_MSG_ATTRIBUTE(
"The variable will be unavailable from Objective C in a future release,"
" but the string will not change.");

/**
* Enum representing the errors raised by Firebase Storage.
Expand Down
8 changes: 6 additions & 2 deletions FirebaseStorage/Tests/Unit/FIRStorageReferenceTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@ - (void)testReferenceWithNonExistentFileFailsWithCompletion {
[expectation fulfill];
XCTAssertNotNil(error);
XCTAssertNil(metadata);

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
XCTAssertEqualObjects(error.domain, FIRStorageErrorDomain);
#pragma clang diagnostic pop
XCTAssertEqual(error.code, FIRStorageErrorCodeUnknown);
NSString *expectedDescription = [NSString
stringWithFormat:@"File at URL: %@ is not reachable. "
Expand All @@ -203,8 +205,10 @@ - (void)testReferenceWithNilFileURLFailsWithCompletion {
[expectation fulfill];
XCTAssertNotNil(error);
XCTAssertNil(metadata);

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
XCTAssertEqualObjects(error.domain, FIRStorageErrorDomain);
#pragma clang diagnostic pop
XCTAssertEqual(error.code, FIRStorageErrorCodeUnknown);
NSString *expectedDescription = [NSString
stringWithFormat:@"File at URL: %@ is not reachable. "
Expand Down
6 changes: 6 additions & 0 deletions FirebaseStorage/Tests/Unit/FIRStorageTokenAuthorizerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,12 @@ - (void)testSuccessfulAuth {
- (void)testUnsuccessfulAuth {
XCTestExpectation *expectation = [self expectationWithDescription:@"testUnsuccessfulAuth"];

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSError *authError = [NSError errorWithDomain:FIRStorageErrorDomain
code:FIRStorageErrorCodeUnauthenticated
userInfo:nil];
#pragma clang diagnostic pop
FIRAuthInteropFake *failedAuth = [[FIRAuthInteropFake alloc] initWithToken:nil
userID:nil
error:authError];
Expand All @@ -109,7 +112,10 @@ - (void)testUnsuccessfulAuth {
NSDictionary<NSString *, NSString *> *headers = self.fetcher.request.allHTTPHeaderFields;
NSString *authHeader = [headers objectForKey:@"Authorization"];
XCTAssertNil(authHeader);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
XCTAssertEqualObjects(error.domain, FIRStorageErrorDomain);
#pragma clang diagnostic pop
XCTAssertEqual(error.code, FIRStorageErrorCodeUnauthenticated);
[expectation fulfill];
}];
Expand Down

0 comments on commit 111d8d6

Please sign in to comment.