Skip to content

Commit 111d8d6

Browse files
authored
Functions and Storage deprecated Error variables (#9569)
* Functions and Storage deprecated Error variables * Test build fixes * one more test build issue * Review * style
1 parent 3837b3e commit 111d8d6

File tree

19 files changed

+66
-27
lines changed

19 files changed

+66
-27
lines changed

FirebaseFunctions/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v8.15.0
2+
- [deprecated] The global variables `FIRFunctionsErrorDomain` and `FIRFunctionsErrorDetailsKey` are
3+
deprecated and will be removed in v9.0.0. (#9569)
4+
15
# v8.9.0
26
- [fixed] Add watchOS support for Swift Package Manager (#8864).
37

FirebaseFunctions/Sources/FIRFunctions+Internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,10 @@ NS_ASSUME_NONNULL_BEGIN
6666

6767
@end
6868

69+
// The error domain for codes in the FIRFunctionsErrorCode enum.
70+
FOUNDATION_EXPORT NSString *const FIRFunctionsErrorDomainInternal;
71+
72+
// The key for finding error details in the NSError userInfo.
73+
FOUNDATION_EXPORT NSString *const FIRFunctionsErrorDetailsKeyInternal;
74+
6975
NS_ASSUME_NONNULL_END

FirebaseFunctions/Sources/FIRFunctions.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ - (void)callFunction:(NSString *)name
296296
}
297297
if (![responseJSON isKindOfClass:[NSDictionary class]]) {
298298
NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"Response was not a dictionary."};
299-
error = [NSError errorWithDomain:FIRFunctionsErrorDomain
299+
error = [NSError errorWithDomain:FIRFunctionsErrorDomainInternal
300300
code:FIRFunctionsErrorCodeInternal
301301
userInfo:userInfo];
302302
if (completion) {
@@ -311,7 +311,7 @@ - (void)callFunction:(NSString *)name
311311
}
312312
if (!dataJSON) {
313313
NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"Response is missing data field."};
314-
error = [NSError errorWithDomain:FIRFunctionsErrorDomain
314+
error = [NSError errorWithDomain:FIRFunctionsErrorDomainInternal
315315
code:FIRFunctionsErrorCodeInternal
316316
userInfo:userInfo];
317317
if (completion) {

FirebaseFunctions/Sources/FUNError.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
NS_ASSUME_NONNULL_BEGIN
2121

2222
NSString *const FIRFunctionsErrorDomain = @"com.firebase.functions";
23+
NSString *const FIRFunctionsErrorDomainInternal = @"com.firebase.functions";
2324
NSString *const FIRFunctionsErrorDetailsKey = @"details";
25+
NSString *const FIRFunctionsErrorDetailsKeyInternal = @"details";
2426

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

139141
NSError *_Nullable FUNErrorForCode(FIRFunctionsErrorCode code) {
140142
NSDictionary *userInfo = @{NSLocalizedDescriptionKey : FUNDescriptionForErrorCode(code)};
141-
return [NSError errorWithDomain:FIRFunctionsErrorDomain code:code userInfo:userInfo];
143+
return [NSError errorWithDomain:FIRFunctionsErrorDomainInternal code:code userInfo:userInfo];
142144
}
143145

144146
NSError *_Nullable FUNErrorForResponse(NSInteger status,
@@ -188,9 +190,9 @@ FIRFunctionsErrorCode FIRFunctionsErrorCodeForHTTPStatus(NSInteger status) {
188190
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
189191
userInfo[NSLocalizedDescriptionKey] = description;
190192
if (details) {
191-
userInfo[FIRFunctionsErrorDetailsKey] = details;
193+
userInfo[FIRFunctionsErrorDetailsKeyInternal] = details;
192194
}
193-
return [NSError errorWithDomain:FIRFunctionsErrorDomain code:code userInfo:userInfo];
195+
return [NSError errorWithDomain:FIRFunctionsErrorDomainInternal code:code userInfo:userInfo];
194196
}
195197

196198
NS_ASSUME_NONNULL_END

FirebaseFunctions/Sources/FUNSerializer.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#import "FirebaseFunctions/Sources/FUNSerializer.h"
1616

17+
#import "FirebaseFunctions/Sources/FIRFunctions+Internal.h"
1718
#import "FirebaseFunctions/Sources/FUNUsageValidation.h"
1819
#import "FirebaseFunctions/Sources/Public/FirebaseFunctions/FIRError.h"
1920

@@ -137,7 +138,7 @@ - (id)encode:(id)object {
137138
NSDictionary *userInfo = @{
138139
NSLocalizedDescriptionKey : description,
139140
};
140-
return [NSError errorWithDomain:FIRFunctionsErrorDomain
141+
return [NSError errorWithDomain:FIRFunctionsErrorDomainInternal
141142
code:FIRFunctionsErrorCodeInternal
142143
userInfo:userInfo];
143144
}

FirebaseFunctions/Sources/Public/FirebaseFunctions/FIRError.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717
NS_ASSUME_NONNULL_BEGIN
1818

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

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

2933
/**

FirebaseFunctions/Tests/Integration/FIRIntegrationTests.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ - (void)testExplicitError {
208208
XCTAssertEqual(FIRFunctionsErrorCodeOutOfRange, error.code);
209209
XCTAssertEqualObjects(@"explicit nope", error.userInfo[NSLocalizedDescriptionKey]);
210210
NSDictionary *expectedDetails = @{@"start" : @10, @"end" : @20, @"long" : @30L};
211-
XCTAssertEqualObjects(expectedDetails, error.userInfo[FIRFunctionsErrorDetailsKey]);
211+
XCTAssertEqualObjects(expectedDetails, error.userInfo[@"details"]);
212212
[expectation fulfill];
213213
}];
214214
[self waitForExpectations:@[ expectation ] timeout:10];
@@ -235,7 +235,7 @@ - (void)testTimeout {
235235
XCTAssertNotNil(error);
236236
XCTAssertEqual(FIRFunctionsErrorCodeDeadlineExceeded, error.code);
237237
XCTAssertEqualObjects(@"DEADLINE EXCEEDED", error.userInfo[NSLocalizedDescriptionKey]);
238-
XCTAssertNil(error.userInfo[FIRFunctionsErrorDetailsKey]);
238+
XCTAssertNil(error.userInfo[@"details"]);
239239
[expectation fulfill];
240240
}];
241241
[self waitForExpectations:@[ expectation ] timeout:10];

FirebaseFunctions/Tests/SwiftIntegration/IntegrationTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ class IntegrationTests: XCTestCase {
377377
XCTAssertEqual(FunctionsErrorCode.outOfRange.rawValue, error.code)
378378
XCTAssertEqual("explicit nope", error.localizedDescription)
379379
XCTAssertEqual(["start": 10 as Int32, "end": 20 as Int32, "long": 30],
380-
error.userInfo[FunctionsErrorDetailsKey] as! [String: Int32])
380+
error.userInfo["details"] as! [String: Int32])
381381
expectation.fulfill()
382382
} catch {
383383
XCTAssert(false, "Failed to unwrap the function result: \(error)")
@@ -399,7 +399,7 @@ class IntegrationTests: XCTestCase {
399399
XCTAssertEqual(FunctionsErrorCode.outOfRange.rawValue, error.code)
400400
XCTAssertEqual("explicit nope", error.localizedDescription)
401401
XCTAssertEqual(["start": 10 as Int32, "end": 20 as Int32, "long": 30],
402-
error.userInfo[FunctionsErrorDetailsKey] as! [String: Int32])
402+
error.userInfo["details"] as! [String: Int32])
403403
return
404404
}
405405
XCTAssertFalse(true, "Failed to throw error for missing result")
@@ -451,7 +451,7 @@ class IntegrationTests: XCTestCase {
451451
let error = try XCTUnwrap(error! as NSError)
452452
XCTAssertEqual(FunctionsErrorCode.deadlineExceeded.rawValue, error.code)
453453
XCTAssertEqual("DEADLINE EXCEEDED", error.localizedDescription)
454-
XCTAssertNil(error.userInfo[FunctionsErrorDetailsKey])
454+
XCTAssertNil(error.userInfo["details"])
455455
expectation.fulfill()
456456
} catch {
457457
XCTAssert(false, "Failed to unwrap the function result: \(error)")
@@ -473,7 +473,7 @@ class IntegrationTests: XCTestCase {
473473
let error = try XCTUnwrap(error) as NSError
474474
XCTAssertEqual(FunctionsErrorCode.deadlineExceeded.rawValue, error.code)
475475
XCTAssertEqual("DEADLINE EXCEEDED", error.localizedDescription)
476-
XCTAssertNil(error.userInfo[FunctionsErrorDetailsKey])
476+
XCTAssertNil(error.userInfo["details"])
477477
return
478478
}
479479
XCTAssertFalse(true, "Failed to throw error for missing result")

FirebaseFunctions/Tests/Unit/FUNSerializerTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ - (void)testDecodeInvalidLong {
8888
NSNumber *actual = [serializer decode:input error:&error];
8989
XCTAssertNil(actual);
9090
XCTAssertNotNil(error);
91-
XCTAssertEqualObjects(FIRFunctionsErrorDomain, error.domain);
91+
XCTAssertEqualObjects(@"com.firebase.functions", error.domain);
9292
XCTAssertEqual(FIRFunctionsErrorCodeInternal, error.code);
9393
}
9494

FirebaseFunctionsSwift/Tests/IntegrationTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ class IntegrationTests: XCTestCase {
429429
XCTAssertEqual(FunctionsErrorCode.outOfRange.rawValue, error.code)
430430
XCTAssertEqual("explicit nope", error.localizedDescription)
431431
XCTAssertEqual(["start": 10 as Int32, "end": 20 as Int32, "long": 30],
432-
error.userInfo[FunctionsErrorDetailsKey] as! [String: Int32])
432+
error.userInfo["details"] as! [String: Int32])
433433
expectation.fulfill()
434434
return
435435
}
@@ -454,7 +454,7 @@ class IntegrationTests: XCTestCase {
454454
XCTAssertEqual(FunctionsErrorCode.outOfRange.rawValue, error.code)
455455
XCTAssertEqual("explicit nope", error.localizedDescription)
456456
XCTAssertEqual(["start": 10 as Int32, "end": 20 as Int32, "long": 30],
457-
error.userInfo[FunctionsErrorDetailsKey] as! [String: Int32])
457+
error.userInfo["details"] as! [String: Int32])
458458
}
459459
}
460460
#endif
@@ -514,7 +514,7 @@ class IntegrationTests: XCTestCase {
514514
let error = error as NSError
515515
XCTAssertEqual(FunctionsErrorCode.deadlineExceeded.rawValue, error.code)
516516
XCTAssertEqual("DEADLINE EXCEEDED", error.localizedDescription)
517-
XCTAssertNil(error.userInfo[FunctionsErrorDetailsKey])
517+
XCTAssertNil(error.userInfo["details"])
518518
expectation.fulfill()
519519
return
520520
}
@@ -539,7 +539,7 @@ class IntegrationTests: XCTestCase {
539539
let error = error as NSError
540540
XCTAssertEqual(FunctionsErrorCode.deadlineExceeded.rawValue, error.code)
541541
XCTAssertEqual("DEADLINE EXCEEDED", error.localizedDescription)
542-
XCTAssertNil(error.userInfo[FunctionsErrorDetailsKey])
542+
XCTAssertNil(error.userInfo["details"])
543543
}
544544
}
545545
#endif

FirebaseStorage/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 8.15.0
2+
- [deprecated] The global variable `FIRStorageErrorDomain` is deprecated and will
3+
be removed in a future release (#9569).
4+
15
# 8.5.0
26
- [fixed] Fixed an issue where Storage could not connect to local emulators using
37
http (#8389).

FirebaseStorage/Sources/FIRStorageConstants.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
NSString *const kFIRStorageResponseBody = @"ResponseBody";
4040

4141
NSString *const FIRStorageErrorDomain = @"FIRStorageErrorDomain";
42+
NSString *const FIRStorageErrorDomainInternal = @"FIRStorageErrorDomain";
4243

4344
NSString *const kFIRStorageInvalidDataFormat = @"Invalid data returned from the server: %@";
4445
NSString *const kFIRStorageInvalidObserverStatus =

FirebaseStorage/Sources/FIRStorageErrors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,6 @@ NS_ASSUME_NONNULL_BEGIN
6767

6868
@end
6969

70+
FOUNDATION_EXPORT NSString *const FIRStorageErrorDomainInternal;
71+
7072
NS_ASSUME_NONNULL_END

FirebaseStorage/Sources/FIRStorageErrors.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ + (NSError *)errorWithCode:(FIRStorageErrorCode)code
113113

114114
errorDictionary[NSLocalizedDescriptionKey] = errorMessage;
115115

116-
NSError *err = [NSError errorWithDomain:FIRStorageErrorDomain code:code userInfo:errorDictionary];
116+
NSError *err = [NSError errorWithDomain:FIRStorageErrorDomainInternal
117+
code:code
118+
userInfo:errorDictionary];
117119
return err;
118120
}
119121

@@ -182,7 +184,7 @@ + (NSError *)errorWithInvalidRequest:(NSData *)request {
182184
}
183185

184186
+ (NSError *)errorWithCustomMessage:(NSString *)errorMessage {
185-
return [NSError errorWithDomain:FIRStorageErrorDomain
187+
return [NSError errorWithDomain:FIRStorageErrorDomainInternal
186188
code:FIRStorageErrorCodeUnknown
187189
userInfo:@{NSLocalizedDescriptionKey : errorMessage}];
188190
}

FirebaseStorage/Sources/FIRStorageUploadTask.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ - (BOOL)isContentToUploadValid:(NSError **)outError {
212212
userInfo[NSUnderlyingErrorKey] = fileReachabilityError;
213213
}
214214

215-
*outError = [NSError errorWithDomain:FIRStorageErrorDomain
215+
*outError = [NSError errorWithDomain:FIRStorageErrorDomainInternal
216216
code:FIRStorageErrorCodeUnknown
217217
userInfo:userInfo];
218218
}

FirebaseStorage/Sources/FIRStorageUtils.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ + (NSString *)encodedURLForPath:(FIRStoragePath *)path {
133133
}
134134

135135
+ (NSError *)storageErrorWithDescription:(NSString *)description code:(NSInteger)code {
136-
return [NSError errorWithDomain:FIRStorageErrorDomain
136+
return [NSError errorWithDomain:FIRStorageErrorDomainInternal
137137
code:code
138138
userInfo:@{NSLocalizedDescriptionKey : description}];
139139
}

FirebaseStorage/Sources/Public/FirebaseStorage/FIRStorageConstants.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ typedef NS_ENUM(NSInteger, FIRStorageTaskStatus) {
112112
/**
113113
* Firebase Storage error domain.
114114
*/
115-
FOUNDATION_EXPORT NSString *const FIRStorageErrorDomain NS_SWIFT_NAME(StorageErrorDomain);
115+
FOUNDATION_EXPORT NSString *const FIRStorageErrorDomain NS_SWIFT_NAME(StorageErrorDomain)
116+
DEPRECATED_MSG_ATTRIBUTE(
117+
"The variable will be unavailable from Objective C in a future release,"
118+
" but the string will not change.");
116119

117120
/**
118121
* Enum representing the errors raised by Firebase Storage.

FirebaseStorage/Tests/Unit/FIRStorageReferenceTests.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ - (void)testReferenceWithNonExistentFileFailsWithCompletion {
176176
[expectation fulfill];
177177
XCTAssertNotNil(error);
178178
XCTAssertNil(metadata);
179-
179+
#pragma clang diagnostic push
180+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
180181
XCTAssertEqualObjects(error.domain, FIRStorageErrorDomain);
182+
#pragma clang diagnostic pop
181183
XCTAssertEqual(error.code, FIRStorageErrorCodeUnknown);
182184
NSString *expectedDescription = [NSString
183185
stringWithFormat:@"File at URL: %@ is not reachable. "
@@ -203,8 +205,10 @@ - (void)testReferenceWithNilFileURLFailsWithCompletion {
203205
[expectation fulfill];
204206
XCTAssertNotNil(error);
205207
XCTAssertNil(metadata);
206-
208+
#pragma clang diagnostic push
209+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
207210
XCTAssertEqualObjects(error.domain, FIRStorageErrorDomain);
211+
#pragma clang diagnostic pop
208212
XCTAssertEqual(error.code, FIRStorageErrorCodeUnknown);
209213
NSString *expectedDescription = [NSString
210214
stringWithFormat:@"File at URL: %@ is not reachable. "

FirebaseStorage/Tests/Unit/FIRStorageTokenAuthorizerTests.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ - (void)testSuccessfulAuth {
8686
- (void)testUnsuccessfulAuth {
8787
XCTestExpectation *expectation = [self expectationWithDescription:@"testUnsuccessfulAuth"];
8888

89+
#pragma clang diagnostic push
90+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
8991
NSError *authError = [NSError errorWithDomain:FIRStorageErrorDomain
9092
code:FIRStorageErrorCodeUnauthenticated
9193
userInfo:nil];
94+
#pragma clang diagnostic pop
9295
FIRAuthInteropFake *failedAuth = [[FIRAuthInteropFake alloc] initWithToken:nil
9396
userID:nil
9497
error:authError];
@@ -109,7 +112,10 @@ - (void)testUnsuccessfulAuth {
109112
NSDictionary<NSString *, NSString *> *headers = self.fetcher.request.allHTTPHeaderFields;
110113
NSString *authHeader = [headers objectForKey:@"Authorization"];
111114
XCTAssertNil(authHeader);
115+
#pragma clang diagnostic push
116+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
112117
XCTAssertEqualObjects(error.domain, FIRStorageErrorDomain);
118+
#pragma clang diagnostic pop
113119
XCTAssertEqual(error.code, FIRStorageErrorCodeUnauthenticated);
114120
[expectation fulfill];
115121
}];

0 commit comments

Comments
 (0)