Skip to content

Commit 337b1ad

Browse files
[google_sign_in] Don't crash a misconfigured iOS app (#9486)
In flutter/plugins#1180 the plugin was deliberately made to crash when misconfigured. The reasoning was that the app shouldn't be released this way, which is true, but crashing the entire app means that a developer has to use Xcode to debug the app to understand what's happening, which is a very poor user experience. The PR indicated that the error would be printed from the Dart side after that PR, but that's not actually what happens; method channel returns are asynchronous, whereas crashing the app on the native side with an unhandled exception happens immediately, so even though the native side does call the completion, the async process of that completion being received on the Dart side as a `PlatformException` was never happening, and the crash was silent outside the context of a native debugger. This removes the throw, so that it can be received as a Dart exception, which is much easier for most developers to debug. ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent cba2e90 commit 337b1ad

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

packages/google_sign_in/google_sign_in_ios/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 6.0.1
2+
3+
* Returns configuration errors as `PlatformException`s in Dart instead of
4+
crashing the app.
5+
16
## 6.0.0
27

38
* **BREAKING CHANGE**: Switches to implementing version 3.0 of the platform

packages/google_sign_in/google_sign_in_ios/darwin/Tests/GoogleSignInTests.m

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -371,26 +371,26 @@ - (void)testSignInError {
371371
[self waitForExpectationsWithTimeout:5.0 handler:nil];
372372
}
373373

374-
- (void)testSignInException {
374+
- (void)testSignInExceptionReturnsError {
375375
OCMExpect([self configureMock:self.mockSignIn
376376
forSignInWithHint:OCMOCK_ANY
377377
additionalScopes:OCMOCK_ANY
378378
completion:OCMOCK_ANY])
379379
.andThrow([NSException exceptionWithName:@"MockName" reason:@"MockReason" userInfo:nil]);
380380

381-
__block FlutterError *error;
382-
XCTAssertThrows([self.plugin
383-
signInWithScopeHint:@[]
384-
nonce:nil
385-
completion:^(FSISignInResult *result, FlutterError *signInError) {
386-
// Unexpected errors, such as runtime exceptions, are returned as FlutterError.
387-
XCTAssertNil(result);
388-
error = signInError;
389-
}]);
390-
391-
XCTAssertEqualObjects(error.code, @"google_sign_in");
392-
XCTAssertEqualObjects(error.message, @"MockReason");
393-
XCTAssertEqualObjects(error.details, @"MockName");
381+
XCTestExpectation *expectation = [self expectationWithDescription:@"completion called"];
382+
[self.plugin signInWithScopeHint:@[]
383+
nonce:nil
384+
completion:^(FSISignInResult *result, FlutterError *error) {
385+
// Unexpected errors, such as runtime exceptions, are returned as
386+
// FlutterError.
387+
XCTAssertNil(result);
388+
XCTAssertEqualObjects(error.code, @"google_sign_in");
389+
XCTAssertEqualObjects(error.message, @"MockReason");
390+
XCTAssertEqualObjects(error.details, @"MockName");
391+
[expectation fulfill];
392+
}];
393+
[self waitForExpectationsWithTimeout:5.0 handler:nil];
394394
}
395395

396396
#pragma mark - refreshedAuthorizationTokens

packages/google_sign_in/google_sign_in_ios/darwin/google_sign_in_ios/Sources/google_sign_in_ios/FLTGoogleSignInPlugin.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ - (void)signInWithScopeHint:(NSArray<NSString *> *)scopeHint
196196
}];
197197
} @catch (NSException *e) {
198198
completion(nil, [FlutterError errorWithCode:@"google_sign_in" message:e.reason details:e.name]);
199-
[e raise];
200199
}
201200
}
202201

packages/google_sign_in/google_sign_in_ios/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_sign_in_ios
22
description: iOS implementation of the google_sign_in plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/google_sign_in/google_sign_in_ios
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22
5-
version: 6.0.0
5+
version: 6.0.1
66

77
environment:
88
sdk: ^3.6.0

0 commit comments

Comments
 (0)