-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[pigeon] Add errors for ProxyAPI callback methods and null instances when reading in a ProxyApiBaseCodec #8567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
dfc15f2
ed6e1f6
45cf10b
6dbf647
a5fb30e
3d3e63c
7fbc58f
79b802f
4229dba
4c06e7c
56c2dd4
2e40742
a3c219e
2c3c947
4803803
b32a5da
61aab9f
b4553a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3057,7 +3057,8 @@ abstract class PigeonApiProxyApiTestClass( | |
| return | ||
| } | ||
| if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { | ||
| Result.success(Unit) | ||
| callback(Result.success(Unit)) | ||
| return | ||
|
||
| return | ||
| } | ||
| callback( | ||
|
|
@@ -4049,7 +4050,8 @@ abstract class PigeonApiProxyApiSuperClass( | |
| return | ||
| } | ||
| if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { | ||
| Result.success(Unit) | ||
| callback(Result.success(Unit)) | ||
| return | ||
| return | ||
| } | ||
| val pigeon_identifierArg = | ||
|
|
@@ -4089,7 +4091,8 @@ open class PigeonApiProxyApiInterface( | |
| return | ||
| } | ||
| if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { | ||
| Result.success(Unit) | ||
| callback(Result.success(Unit)) | ||
| return | ||
| return | ||
| } | ||
| val pigeon_identifierArg = | ||
|
|
@@ -4259,7 +4262,8 @@ abstract class PigeonApiClassWithApiRequirement( | |
| return | ||
| } | ||
| if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { | ||
| Result.success(Unit) | ||
| callback(Result.success(Unit)) | ||
| return | ||
| return | ||
| } | ||
| val pigeon_identifierArg = | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -362,7 +362,7 @@ private class ProxyApiTestsPigeonInstanceManagerApi { | |||
| let details: String? = nilOrValue(listResponse[2]) | ||||
| completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) | ||||
| } else { | ||||
| completion(.success(Void())) | ||||
| completion(.success(())) | ||||
| } | ||||
| } | ||||
| } | ||||
|
|
@@ -2817,7 +2817,7 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass { | |||
| return | ||||
| } | ||||
| if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { | ||||
| completion(.success(Void())) | ||||
| completion(.success(())) | ||||
| return | ||||
| } | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same structural question for this whole method (I can't comment on the method declaration since it's outside of the change context): could this have a simple return instead of a completion, reducing the complexity?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed the code to use a
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue isn't the return, it's that (as the Kotlin bug demonstrated) having a function use an async callback is inherently more error-prone, because the compiler will enforce that you return exactly once, but callbacks don't. Since we don't need any async behavior here, the method would be safer if it used a return value instead of a callback.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but technically the method is making a async call when it makes the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not following where there's an async step in this method, looking at the code. The structure of func pigeonNewInstance(
pigeonInstance: ProxyApiTestClass,
completion: @escaping (Result<Void, ProxyApiTestsError>) -> Void
) {
if pigeonRegistrar.ignoreCallsToDart {
completion(...)
} else if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) {
completion(...)
} else {
completion(...)
}
}In every branch, it's just synchronously calling completion. I don't see any reason (other than the logistics of the generator logic helper function discussed in the other thread) it couldn't be pigeonNewInstance(pigeonInstance: ProxyApiTestClass) -> Result<Void, ProxyApiTestsError>with every
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For most classes, the final completion is done inside of a packages/packages/pigeon/platform_tests/test_plugin/ios/Classes/ProxyApiTests.gen.swift Line 3885 in 2c3c947
} else {
let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance(
pigeonInstance as AnyObject)
let binaryMessenger = pigeonRegistrar.binaryMessenger
let codec = pigeonRegistrar.codec
let channelName: String =
"dev.flutter.pigeon.pigeon_integration_tests.ProxyApiSuperClass.pigeon_newInstance"
let channel = FlutterBasicMessageChannel(
name: channelName, binaryMessenger: binaryMessenger, codec: codec)
channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in
guard let listResponse = response as? [Any?] else {
completion(.failure(createConnectionError(withChannelName: channelName)))
return
}
if listResponse.count > 1 {
let code: String = listResponse[0] as! String
let message: String? = nilOrValue(listResponse[1])
let details: String? = nilOrValue(listResponse[2])
completion(.failure(ProxyApiTestsError(code: code, message: message, details: details)))
} else {
completion(.success(()))
}
}
}Its based on whether the Dart class has required callback methods to be implemented. If yes, this final completion synchronously returns an error.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I see now. Sorry about that; I missed that there were two different forms of it. |
||||
| completion( | ||||
|
|
@@ -2859,7 +2859,7 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass { | |||
| let details: String? = nilOrValue(listResponse[2]) | ||||
| completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) | ||||
| } else { | ||||
| completion(.success(Void())) | ||||
| completion(.success(())) | ||||
| } | ||||
| } | ||||
| } | ||||
|
|
@@ -2930,7 +2930,7 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass { | |||
| let details: String? = nilOrValue(listResponse[2]) | ||||
| completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) | ||||
| } else { | ||||
| completion(.success(Void())) | ||||
| completion(.success(())) | ||||
| } | ||||
| } | ||||
| } | ||||
|
|
@@ -3756,7 +3756,7 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass { | |||
| let details: String? = nilOrValue(listResponse[2]) | ||||
| completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) | ||||
| } else { | ||||
| completion(.success(Void())) | ||||
| completion(.success(())) | ||||
| } | ||||
| } | ||||
| } | ||||
|
|
@@ -3885,7 +3885,7 @@ final class PigeonApiProxyApiSuperClass: PigeonApiProtocolProxyApiSuperClass { | |||
| return | ||||
| } | ||||
| if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { | ||||
| completion(.success(Void())) | ||||
| completion(.success(())) | ||||
| return | ||||
| } | ||||
| let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( | ||||
|
|
@@ -3907,7 +3907,7 @@ final class PigeonApiProxyApiSuperClass: PigeonApiProtocolProxyApiSuperClass { | |||
| let details: String? = nilOrValue(listResponse[2]) | ||||
| completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) | ||||
| } else { | ||||
| completion(.success(Void())) | ||||
| completion(.success(())) | ||||
| } | ||||
| } | ||||
| } | ||||
|
|
@@ -3945,7 +3945,7 @@ final class PigeonApiProxyApiInterface: PigeonApiProtocolProxyApiInterface { | |||
| return | ||||
| } | ||||
| if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { | ||||
| completion(.success(Void())) | ||||
| completion(.success(())) | ||||
| return | ||||
| } | ||||
| let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( | ||||
|
|
@@ -3967,7 +3967,7 @@ final class PigeonApiProxyApiInterface: PigeonApiProtocolProxyApiInterface { | |||
| let details: String? = nilOrValue(listResponse[2]) | ||||
| completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) | ||||
| } else { | ||||
| completion(.success(Void())) | ||||
| completion(.success(())) | ||||
| } | ||||
| } | ||||
| } | ||||
|
|
@@ -4000,7 +4000,7 @@ final class PigeonApiProxyApiInterface: PigeonApiProtocolProxyApiInterface { | |||
| let details: String? = nilOrValue(listResponse[2]) | ||||
| completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) | ||||
| } else { | ||||
| completion(.success(Void())) | ||||
| completion(.success(())) | ||||
| } | ||||
| } | ||||
| } | ||||
|
|
@@ -4131,7 +4131,7 @@ final class PigeonApiClassWithApiRequirement: PigeonApiProtocolClassWithApiRequi | |||
| return | ||||
| } | ||||
| if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) { | ||||
| completion(.success(Void())) | ||||
| completion(.success(())) | ||||
| return | ||||
| } | ||||
| let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( | ||||
|
|
@@ -4153,7 +4153,7 @@ final class PigeonApiClassWithApiRequirement: PigeonApiProtocolClassWithApiRequi | |||
| let details: String? = nilOrValue(listResponse[2]) | ||||
| completion(.failure(ProxyApiTestsError(code: code, message: message, details: details))) | ||||
| } else { | ||||
| completion(.success(Void())) | ||||
| completion(.success(())) | ||||
| } | ||||
| } | ||||
| } | ||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is corresponding generator line?