Skip to content

Commit 63bc5cd

Browse files
[google_sign_in] Remove the Objective-C exception catcher (#13156)
Removes the Objective-C `ExceptionCatcher` so `google_sign_in_ios` can be Swift-only. `signIn` / `addScopes` now call the GID SDK directly instead of mapping `NSException` into `PigeonError`. The SDK only throws for deterministic misconfiguration (missing `GIDClientID`, URL scheme, or client ID). Those fail the same way every time and show up on any login-path test, so keeping a hybrid package to surface them as Dart errors is not worth it. Missing presenter is unchanged: `GIDSignInWrapper` still returns a Dart error without calling the SDK. Deletes the `google_sign_in_ios_objc` SPM target and the CocoaPods placeholder header. The podspec is Swift-only (`**/*.swift`). Exception-injection tests (`signInExceptionReturnsError`, `addScopesException`) are removed because they would crash without the catcher. Bumps `google_sign_in_ios` to 6.3.7. Follow-up to #12658. Fixes #193464 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^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 67bf684 commit 63bc5cd

9 files changed

Lines changed: 19 additions & 182 deletions

File tree

‎packages/google_sign_in/google_sign_in_ios/CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 6.3.7
2+
3+
* Converts the plugin to Swift-only by removing the Objective-C exception catcher. SDK configuration failures now crash natively instead of being reported as Dart errors.
4+
15
## 6.3.6
26

37
* Converts the Pigeon host API from Objective-C to Swift.

‎packages/google_sign_in/google_sign_in_ios/darwin/Tests/GoogleSignInTests.swift‎

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ class TestViewProvider: ViewProvider {
2828
class TestSignIn: NSObject, GIDSignInProtocol {
2929
var configuration: GIDConfiguration?
3030

31-
// To cause methods to throw an exception.
32-
var exception: NSException?
33-
3431
// Results to use in completion callbacks.
3532
var user: (any GIDGoogleUserProtocol)?
3633
var error: Error?
@@ -59,9 +56,6 @@ class TestSignIn: NSObject, GIDSignInProtocol {
5956
}
6057

6158
func restorePreviousSignIn(completion: (((any GIDGoogleUserProtocol)?, Error?) -> Void)?) {
62-
if let exception {
63-
exception.raise()
64-
}
6559
if let user {
6660
completion?(user, nil)
6761
} else {
@@ -74,9 +68,6 @@ class TestSignIn: NSObject, GIDSignInProtocol {
7468
}
7569

7670
func disconnect(completion: ((Error?) -> Void)?) {
77-
if let exception {
78-
exception.raise()
79-
}
8071
completion?(error)
8172
}
8273

@@ -88,9 +79,6 @@ class TestSignIn: NSObject, GIDSignInProtocol {
8879
nonce: String?,
8980
completion: ((GIDSignInResultProtocol?, Error?) -> Void)?
9081
) {
91-
if let exception {
92-
exception.raise()
93-
}
9482
self.presentingViewController = presentingViewController
9583
self.hint = hint
9684
self.additionalScopes = additionalScopes
@@ -109,9 +97,6 @@ class TestSignIn: NSObject, GIDSignInProtocol {
10997
nonce: String?,
11098
completion: (((any GIDSignInResultProtocol)?, Error?) -> Void)?
11199
) {
112-
if let exception {
113-
exception.raise()
114-
}
115100
self.presentingWindow = presentingWindow
116101
self.hint = hint
117102
self.additionalScopes = additionalScopes
@@ -178,9 +163,6 @@ class TestGoogleUser: GIDGoogleUserProtocol {
178163
var refreshToken: any GIDTokenProtocol = TestToken("Refresh")
179164
var idToken: (any GIDTokenProtocol)?
180165

181-
// An exception to throw from methods.
182-
var exception: NSException?
183-
184166
// The result to return from addScopes(_:presenting:completion:).
185167
var result: (any GIDSignInResultProtocol)?
186168

@@ -200,9 +182,6 @@ class TestGoogleUser: GIDGoogleUserProtocol {
200182
}
201183

202184
func refreshTokensIfNeeded(completion: @escaping ((any GIDGoogleUserProtocol)?, Error?) -> Void) {
203-
if let exception {
204-
exception.raise()
205-
}
206185
completion(self.error == nil ? self : nil, self.error)
207186
}
208187

@@ -214,9 +193,6 @@ class TestGoogleUser: GIDGoogleUserProtocol {
214193
) {
215194
self.requestedScopes = scopes
216195
self.presentingViewController = presentingViewController
217-
if let exception {
218-
exception.raise()
219-
}
220196
completion?(self.error == nil ? self.result : nil, self.error)
221197
}
222198
#elseif os(macOS)
@@ -227,9 +203,6 @@ class TestGoogleUser: GIDGoogleUserProtocol {
227203
) {
228204
self.requestedScopes = scopes
229205
self.presentingWindow = presentingWindow
230-
if let exception {
231-
exception.raise()
232-
}
233206
completion?(self.error == nil ? self.result : nil, self.error)
234207
}
235208
#endif
@@ -585,33 +558,6 @@ struct GoogleSignInPluginTests {
585558
}
586559
}
587560

588-
@Test func signInExceptionReturnsError() async {
589-
let (plugin, fakeSignIn) = createTestPlugin()
590-
fakeSignIn.exception = NSException(
591-
name: NSExceptionName(rawValue: "MockName"),
592-
reason: "MockReason",
593-
userInfo: nil)
594-
595-
await confirmation("completion called") { confirmed in
596-
plugin.signIn(scopeHint: [], nonce: nil) { result in
597-
switch result {
598-
case .success:
599-
Issue.record("Expected a PigeonError for the runtime exception")
600-
case .failure(let error):
601-
// Unexpected errors, such as runtime exceptions, are returned as
602-
// PigeonError.
603-
guard let pigeonError = error as? PigeonError else {
604-
Issue.record("Expected PigeonError, got \(error)")
605-
break
606-
}
607-
#expect(pigeonError.code == "google_sign_in")
608-
#expect(pigeonError.message == "MockReason")
609-
#expect(pigeonError.details as? String == "MockName")
610-
}
611-
confirmed()
612-
}
613-
}
614-
}
615561
}
616562

617563
@Suite("refreshedAuthorizationTokens") struct RefreshTests {
@@ -828,33 +774,6 @@ struct GoogleSignInPluginTests {
828774
}
829775
}
830776

831-
@Test func addScopesException() async {
832-
let (plugin, _) = createTestPlugin()
833-
let fakeUser = addSignedInUser(to: plugin)
834-
835-
fakeUser.exception = NSException(
836-
name: NSExceptionName(rawValue: "MockName"),
837-
reason: "MockReason",
838-
userInfo: nil)
839-
840-
await confirmation("completion called") { confirmed in
841-
plugin.addScopes([], forUser: fakeUser.userID!) { result in
842-
switch result {
843-
case .success:
844-
Issue.record("Expected a PigeonError for the runtime exception")
845-
case .failure(let error):
846-
guard let pigeonError = error as? PigeonError else {
847-
Issue.record("Expected PigeonError, got \(error)")
848-
break
849-
}
850-
#expect(pigeonError.code == "request_scopes")
851-
#expect(pigeonError.message == "MockReason")
852-
#expect(pigeonError.details as? String == "MockName")
853-
}
854-
confirmed()
855-
}
856-
}
857-
}
858777
}
859778

860779
@Suite("urlHandling")

‎packages/google_sign_in/google_sign_in_ios/darwin/google_sign_in_ios.podspec‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ Enables Google Sign-In in Flutter apps.
1212
s.license = { :type => 'BSD', :file => '../LICENSE' }
1313
s.author = { 'Flutter Team' => '[email protected]' }
1414
s.source = { :http => 'https://github.com/flutter/packages/tree/main/packages/google_sign_in/google_sign_in_ios' }
15-
# Remaining Objective-C is ExceptionCatcher (NSException can't be caught from
16-
# Swift) plus a CocoaPods placeholder header. SwiftPM needs a separate Obj-C
17-
# target; CocoaPods compiles both into one pod.
18-
s.source_files = 'google_sign_in_ios/Sources/google_sign_in_ios*/**/*.{h,m,swift}'
19-
s.public_header_files = 'google_sign_in_ios/Sources/google_sign_in_ios_objc/include/**/*.h'
15+
s.source_files = 'google_sign_in_ios/Sources/google_sign_in_ios/**/*.swift'
2016
s.swift_version = '5.0'
2117
s.xcconfig = {
2218
'LIBRARY_SEARCH_PATHS' => '$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)/ $(SDKROOT)/usr/lib/swift',

‎packages/google_sign_in/google_sign_in_ios/darwin/google_sign_in_ios/Package.swift‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,11 @@ let package = Package(
2424
.target(
2525
name: "google_sign_in_ios",
2626
dependencies: [
27-
.product(name: "GoogleSignIn", package: "GoogleSignIn-iOS"),
28-
"google_sign_in_ios_objc",
27+
.product(name: "GoogleSignIn", package: "GoogleSignIn-iOS")
2928
],
3029
resources: [
3130
.process("Resources")
3231
]
33-
),
34-
// Swift cannot catch NSException, so ExceptionCatcher.m stays in a separate
35-
// Objective-C target. That target also holds the CocoaPods placeholder
36-
// header required to import google_sign_in_ios.h.
37-
.target(
38-
name: "google_sign_in_ios_objc",
39-
publicHeadersPath: "include/google_sign_in_ios_objc"
40-
),
32+
)
4133
]
4234
)

‎packages/google_sign_in/google_sign_in_ios/darwin/google_sign_in_ios/Sources/google_sign_in_ios/GoogleSignInPlugin.swift‎

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import Darwin
66
import Foundation
77
import GoogleSignIn
88

9-
#if canImport(google_sign_in_ios_objc)
10-
import google_sign_in_ios_objc
11-
#endif
12-
139
#if os(macOS)
1410
import FlutterMacOS
1511
#else
@@ -208,20 +204,14 @@ public final class GoogleSignInPlugin: NSObject, FlutterPlugin, GoogleSignInApi
208204
nonce: String?,
209205
completion: @escaping (Result<SignInResult, Error>) -> Void
210206
) {
211-
let exception = performSignIn(hint: nil, additionalScopes: scopeHint, nonce: nonce) {
207+
performSignIn(hint: nil, additionalScopes: scopeHint, nonce: nonce) {
212208
[weak self] signInResult, error in
213209
self?.handleAuthResult(
214210
user: signInResult?.user,
215211
serverAuthCode: signInResult?.serverAuthCode,
216212
error: error,
217213
completion: completion)
218214
}
219-
if let exception {
220-
completion(
221-
.failure(
222-
PigeonError(
223-
code: "google_sign_in", message: exception.reason, details: exception.name.rawValue)))
224-
}
225215
}
226216

227217
func getRefreshedAuthorizationTokens(
@@ -259,19 +249,13 @@ public final class GoogleSignInPlugin: NSObject, FlutterPlugin, GoogleSignInApi
259249
return
260250
}
261251

262-
let exception = performAddScopes(scopes, for: user) { [weak self] signInResult, error in
252+
performAddScopes(scopes, for: user) { [weak self] signInResult, error in
263253
self?.handleAuthResult(
264254
user: signInResult?.user,
265255
serverAuthCode: signInResult?.serverAuthCode,
266256
error: error,
267257
completion: completion)
268258
}
269-
if let exception {
270-
completion(
271-
.failure(
272-
PigeonError(
273-
code: "request_scopes", message: exception.reason, details: exception.name.rawValue)))
274-
}
275259
}
276260

277261
func signOut() throws {
@@ -294,49 +278,37 @@ public final class GoogleSignInPlugin: NSObject, FlutterPlugin, GoogleSignInApi
294278
// MARK: - Private
295279

296280
/// Wraps the iOS and macOS sign in display methods.
297-
///
298-
/// Returns any `NSException` raised by the SDK, or nil. The exception catcher
299-
/// wraps only the SDK call itself, since Obj-C exception unwinding through
300-
/// Swift frames is undefined behavior.
301281
private func performSignIn(
302282
hint: String?,
303283
additionalScopes: [String]?,
304284
nonce: String?,
305285
completion: @escaping (GIDSignInResultProtocol?, Error?) -> Void
306-
) -> NSException? {
286+
) {
307287
#if os(macOS)
308288
let presenting = viewProvider.view?.window
309289
#else
310290
let presenting = topViewController
311291
#endif
312-
return GoogleSignInCatchException {
313-
self.signIn.signIn(
314-
withPresenting: presenting,
315-
hint: hint,
316-
additionalScopes: additionalScopes,
317-
nonce: nonce,
318-
completion: completion)
319-
}
292+
signIn.signIn(
293+
withPresenting: presenting,
294+
hint: hint,
295+
additionalScopes: additionalScopes,
296+
nonce: nonce,
297+
completion: completion)
320298
}
321299

322300
/// Wraps the iOS and macOS scope addition methods.
323-
///
324-
/// Returns any `NSException` raised by the SDK, or nil. The exception catcher
325-
/// wraps only the SDK call itself, since Obj-C exception unwinding through
326-
/// Swift frames is undefined behavior.
327301
private func performAddScopes(
328302
_ scopes: [String],
329303
for user: any GIDGoogleUserProtocol,
330304
completion: @escaping (GIDSignInResultProtocol?, Error?) -> Void
331-
) -> NSException? {
305+
) {
332306
#if os(macOS)
333307
let presenting = viewProvider.view?.window
334308
#else
335309
let presenting = topViewController
336310
#endif
337-
return GoogleSignInCatchException {
338-
user.addScopes(scopes, presenting: presenting, completion: completion)
339-
}
311+
user.addScopes(scopes, presenting: presenting, completion: completion)
340312
}
341313

342314
/// Returns nil if GoogleService-Info.plist not found and runtimeClientIdentifier is not provided.

‎packages/google_sign_in/google_sign_in_ios/darwin/google_sign_in_ios/Sources/google_sign_in_ios_objc/ExceptionCatcher.m‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎packages/google_sign_in/google_sign_in_ios/darwin/google_sign_in_ios/Sources/google_sign_in_ios_objc/include/google_sign_in_ios/google_sign_in_ios.h‎

Lines changed: 0 additions & 16 deletions
This file was deleted.

‎packages/google_sign_in/google_sign_in_ios/darwin/google_sign_in_ios/Sources/google_sign_in_ios_objc/include/google_sign_in_ios_objc/ExceptionCatcher.h‎

Lines changed: 0 additions & 16 deletions
This file was deleted.

‎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.3.6
5+
version: 6.3.7
66

77
environment:
88
sdk: ^3.11.0

0 commit comments

Comments
 (0)