From 499537d6cfd8c3c6012f2234f27b5d49c3b8d253 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 24 Jun 2025 11:37:27 -0400 Subject: [PATCH] [google_sign_in] Don't crash a misconfigured iOS app In https://github.com/flutter/plugins/pull/1180 the plugin was deliberately designed 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. This removes the throw, so that it can be received as a Dart exception, which is much easier for most developers to debug. --- .../google_sign_in_ios/CHANGELOG.md | 5 ++++ .../darwin/Tests/GoogleSignInTests.m | 28 +++++++++---------- .../FLTGoogleSignInPlugin.m | 1 - .../google_sign_in_ios/pubspec.yaml | 2 +- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/packages/google_sign_in/google_sign_in_ios/CHANGELOG.md b/packages/google_sign_in/google_sign_in_ios/CHANGELOG.md index 6a0cd9dc4ff..fa290a057d8 100644 --- a/packages/google_sign_in/google_sign_in_ios/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_ios/CHANGELOG.md @@ -1,3 +1,8 @@ +## 6.0.1 + +* Returns configuration errors as `PlatformException`s in Dart instead of + crashing the app. + ## 6.0.0 * **BREAKING CHANGE**: Switches to implementing version 3.0 of the platform diff --git a/packages/google_sign_in/google_sign_in_ios/darwin/Tests/GoogleSignInTests.m b/packages/google_sign_in/google_sign_in_ios/darwin/Tests/GoogleSignInTests.m index fa33c254ca6..d80c161d1c4 100644 --- a/packages/google_sign_in/google_sign_in_ios/darwin/Tests/GoogleSignInTests.m +++ b/packages/google_sign_in/google_sign_in_ios/darwin/Tests/GoogleSignInTests.m @@ -371,26 +371,26 @@ - (void)testSignInError { [self waitForExpectationsWithTimeout:5.0 handler:nil]; } -- (void)testSignInException { +- (void)testSignInExceptionReturnsError { OCMExpect([self configureMock:self.mockSignIn forSignInWithHint:OCMOCK_ANY additionalScopes:OCMOCK_ANY completion:OCMOCK_ANY]) .andThrow([NSException exceptionWithName:@"MockName" reason:@"MockReason" userInfo:nil]); - __block FlutterError *error; - XCTAssertThrows([self.plugin - signInWithScopeHint:@[] - nonce:nil - completion:^(FSISignInResult *result, FlutterError *signInError) { - // Unexpected errors, such as runtime exceptions, are returned as FlutterError. - XCTAssertNil(result); - error = signInError; - }]); - - XCTAssertEqualObjects(error.code, @"google_sign_in"); - XCTAssertEqualObjects(error.message, @"MockReason"); - XCTAssertEqualObjects(error.details, @"MockName"); + XCTestExpectation *expectation = [self expectationWithDescription:@"completion called"]; + [self.plugin signInWithScopeHint:@[] + nonce:nil + completion:^(FSISignInResult *result, FlutterError *error) { + // Unexpected errors, such as runtime exceptions, are returned as + // FlutterError. + XCTAssertNil(result); + XCTAssertEqualObjects(error.code, @"google_sign_in"); + XCTAssertEqualObjects(error.message, @"MockReason"); + XCTAssertEqualObjects(error.details, @"MockName"); + [expectation fulfill]; + }]; + [self waitForExpectationsWithTimeout:5.0 handler:nil]; } #pragma mark - refreshedAuthorizationTokens diff --git a/packages/google_sign_in/google_sign_in_ios/darwin/google_sign_in_ios/Sources/google_sign_in_ios/FLTGoogleSignInPlugin.m b/packages/google_sign_in/google_sign_in_ios/darwin/google_sign_in_ios/Sources/google_sign_in_ios/FLTGoogleSignInPlugin.m index 5412429662c..07c392e0771 100644 --- a/packages/google_sign_in/google_sign_in_ios/darwin/google_sign_in_ios/Sources/google_sign_in_ios/FLTGoogleSignInPlugin.m +++ b/packages/google_sign_in/google_sign_in_ios/darwin/google_sign_in_ios/Sources/google_sign_in_ios/FLTGoogleSignInPlugin.m @@ -196,7 +196,6 @@ - (void)signInWithScopeHint:(NSArray *)scopeHint }]; } @catch (NSException *e) { completion(nil, [FlutterError errorWithCode:@"google_sign_in" message:e.reason details:e.name]); - [e raise]; } } diff --git a/packages/google_sign_in/google_sign_in_ios/pubspec.yaml b/packages/google_sign_in/google_sign_in_ios/pubspec.yaml index 6e5cb025024..f38a2eb2c77 100644 --- a/packages/google_sign_in/google_sign_in_ios/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_ios/pubspec.yaml @@ -2,7 +2,7 @@ name: google_sign_in_ios description: iOS implementation of the google_sign_in plugin. repository: https://github.com/flutter/packages/tree/main/packages/google_sign_in/google_sign_in_ios issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22 -version: 6.0.0 +version: 6.0.1 environment: sdk: ^3.6.0