-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[pigeon] Add errors for ProxyAPI callback methods and null instances when reading in a ProxyApiBaseCodec #8567
Merged
auto-submit
merged 18 commits into
flutter:main
from
bparrishMines:pigeon_require_nonnull
Feb 10, 2025
+646
−1,067
Merged
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
dfc15f2
improve error messaging
bparrishMines ed6e1f6
add null check
bparrishMines 45cf10b
fixes
bparrishMines 6dbf647
undo change
bparrishMines a5fb30e
with not will
bparrishMines 3d3e63c
remove non overrides
bparrishMines 7fbc58f
remove unused implementations
bparrishMines 79b802f
Merge branch 'main' of github.com:flutter/packages into pigeon_requir…
bparrishMines 4229dba
add fix for not calling completion
bparrishMines 4c06e7c
fix kotlin
bparrishMines 56c2dd4
Merge branch 'main' of github.com:flutter/packages into pigeon_requir…
bparrishMines 2e40742
improve method structure
bparrishMines a3c219e
undo non proxy api change
bparrishMines 2c3c947
changed my mind and updated other voids
bparrishMines 4803803
unneccssary return call
bparrishMines b32a5da
Merge branch 'main' of github.com:flutter/packages into pigeon_requir…
bparrishMines 61aab9f
fix swift test
bparrishMines b4553a2
change location of space
bparrishMines File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -949,6 +949,9 @@ if (wrapped == nil) { | |
let identifier = self.readValue() | ||
let instance: AnyObject? = pigeonRegistrar.instanceManager.instance( | ||
forIdentifier: identifier is Int64 ? identifier as! Int64 : Int64(identifier as! Int32)) | ||
if instance == nil { | ||
print("Failed to find instance with identifier: \\(identifier!)") | ||
} | ||
return instance | ||
default: | ||
return super.readValue(ofType: type) | ||
|
@@ -1502,7 +1505,7 @@ private func nilOrValue<T>(_ value: Any?) -> T? { | |
} | ||
indent.addScoped('else {', '}', () { | ||
if (returnType.isVoid) { | ||
indent.writeln('completion(.success(Void()))'); | ||
indent.writeln('completion(.success(()))'); | ||
} else { | ||
final String fieldType = _swiftTypeForDartType(returnType); | ||
_writeGenericCasting( | ||
|
@@ -2310,71 +2313,78 @@ private func nilOrValue<T>(_ value: Any?) -> T? { | |
indent.writeScoped('$methodSignature {', '}', () { | ||
indent.writeScoped( | ||
'if pigeonRegistrar.ignoreCallsToDart {', | ||
'}', | ||
'} ', | ||
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. here too |
||
() { | ||
indent.format( | ||
''' | ||
completion( | ||
.failure( | ||
${_getErrorClassName(generatorOptions)}( | ||
code: "ignore-calls-error", | ||
message: "Calls to Dart are being ignored.", details: ""))) | ||
return''', | ||
message: "Calls to Dart are being ignored.", details: "")))''', | ||
); | ||
}, | ||
addTrailingNewline: false, | ||
); | ||
|
||
indent.writeScoped( | ||
'if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) {', | ||
'}', | ||
'else if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) {', | ||
'} ', | ||
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. here |
||
() { | ||
indent.writeln('completion(.success(Void()))'); | ||
indent.writeln('return'); | ||
indent.writeln('completion(.success(()))'); | ||
}, | ||
addTrailingNewline: false, | ||
); | ||
if (api.hasCallbackConstructor()) { | ||
indent.writeln( | ||
'let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeonInstance as AnyObject)', | ||
); | ||
enumerate(api.unattachedFields, (int index, ApiField field) { | ||
final String argName = _getSafeArgumentName(index, field); | ||
indent.writeScoped('else {', '}', () { | ||
if (api.hasCallbackConstructor()) { | ||
indent.writeln( | ||
'let $argName = try! pigeonDelegate.${field.name}(pigeonApi: self, pigeonInstance: pigeonInstance)', | ||
'let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeonInstance as AnyObject)', | ||
); | ||
}); | ||
indent.writeln( | ||
'let binaryMessenger = pigeonRegistrar.binaryMessenger', | ||
); | ||
indent.writeln('let codec = pigeonRegistrar.codec'); | ||
_writeFlutterMethodMessageCall( | ||
indent, | ||
generatorOptions: generatorOptions, | ||
parameters: <Parameter>[ | ||
Parameter( | ||
name: 'pigeonIdentifier', | ||
type: const TypeDeclaration( | ||
baseName: 'int', | ||
isNullable: false, | ||
enumerate(api.unattachedFields, (int index, ApiField field) { | ||
final String argName = _getSafeArgumentName(index, field); | ||
indent.writeln( | ||
'let $argName = try! pigeonDelegate.${field.name}(pigeonApi: self, pigeonInstance: pigeonInstance)', | ||
); | ||
}); | ||
indent.writeln( | ||
'let binaryMessenger = pigeonRegistrar.binaryMessenger', | ||
); | ||
indent.writeln('let codec = pigeonRegistrar.codec'); | ||
_writeFlutterMethodMessageCall( | ||
indent, | ||
generatorOptions: generatorOptions, | ||
parameters: <Parameter>[ | ||
Parameter( | ||
name: 'pigeonIdentifier', | ||
type: const TypeDeclaration( | ||
baseName: 'int', | ||
isNullable: false, | ||
), | ||
), | ||
...api.unattachedFields.map( | ||
(ApiField field) { | ||
return Parameter(name: field.name, type: field.type); | ||
}, | ||
), | ||
], | ||
returnType: const TypeDeclaration.voidDeclaration(), | ||
channelName: makeChannelNameWithStrings( | ||
apiName: api.name, | ||
methodName: newInstanceMethodName, | ||
dartPackageName: dartPackageName, | ||
), | ||
...api.unattachedFields.map( | ||
(ApiField field) { | ||
return Parameter(name: field.name, type: field.type); | ||
}, | ||
), | ||
], | ||
returnType: const TypeDeclaration.voidDeclaration(), | ||
channelName: makeChannelNameWithStrings( | ||
apiName: api.name, | ||
methodName: newInstanceMethodName, | ||
dartPackageName: dartPackageName, | ||
), | ||
); | ||
} else { | ||
indent.writeln( | ||
'print("Error: Attempting to create a new Dart instance of ${api.name}, but the class has a nonnull callback method.")', | ||
); | ||
} | ||
); | ||
} else { | ||
indent.format( | ||
''' | ||
completion( | ||
.failure( | ||
${_getErrorClassName(generatorOptions)}( | ||
code: "new-instance-error", | ||
message: "Error: Attempting to create a new Dart instance of ${api.name}, but the class has a nonnull callback method.", details: "")))''', | ||
); | ||
} | ||
}); | ||
}); | ||
|
||
if (unsupportedPlatforms != null) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Pretty minor nit, but I think it's better to put the spaces before the
else
rather than after the}
since the scoped statement doesn't need it, but theelse
statement does.