-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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] Standardize host api error handling #3234
Conversation
Seems there is at least one failing Java test at the moment. Thanks for putting this pr together! Let me know if you need any assistance with anything moving forward. |
What did I do that caused the pigeon version for
|
Seems unlikely this is from your pr, we just made a major structural change that is most likely causing these issues. I'll look into it to confirm |
I noticed this in the swift generator packages/packages/pigeon/lib/swift_generator.dart Lines 474 to 476 in c0f0a22
Is there a reason why the try-catch statement is explicitly ommited for asynchronous methods? Seems to be the case for kotlin as well, compared to the java & cpp generators which retain the try catch statements for async methods. |
Hi, I was trying to test this new functionality on the Kotlin side, but ran into a problem; for example, after using the kotlin code generation you could have something like this:
where you want to fail it using a FlutterException. However, initializing the exception is not possible currently because the initializer seems private; Should the exception be initiated in a different way for this approach or is there another way how it should be called? |
Yes I only realized that recently, it seems that the access modifier for the |
What's the argument against making an exception specifically for Pigeon? Only Pigeon code would ever handle it; what would be gained by defining it in the engine? |
Arguably we should remove them for Java and C++. For C++ at least, it's largely a legacy of an earlier error handling design that didn't end up being kept. The reason to not have them is that it creates two completely different ways to return errors from async methods (one of which will usually not be useful), which is confusing. If a plugin developer is concerned about exceptions in the synchronous part of their async method implementation they can do their own try/catch, just as they would need to in the rest of it. |
Hmm you are right, it's more sensible to create an exception specifically for pigeon. It's just that the objc/swift side uses I'll follow up with a commit to replace |
|
|
I have been using this PR and there is actually an inconvenience here for iOS and Android. Android/Kotlin: A similar problem arises here as we need to use the I understand that these changes are bigger than this PR but opening a new issue right now before this got merged seemed wrong. |
I'm not sure what you mean by "developer error" since it's not an error to return something other than a
Same here; what does "wrong" mean here? It will work fine. In both cases, it behaves the same as throwing in a sync function. |
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.
Some small comments, but overall this looks great!
@stuartmorgan I think I indeed used the wrong wording in my previous message with too little information to back up my reasoning. The Flutter documentation describes that the PlatformException has a code (An error code) and can have a Message (A human-readable error message, possibly null) and a stacktrace (Native stacktrace for the error, possibly null). |
Please file an issue about that; there's no reasonable way to force synchronous methods to use specific throwable types, so if the existing handling is wrong we need to improve it (e.g., matching MethodChannel handling in Java). Changing the signature for async methods wouldn't be sufficient regardless. |
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.
LGTM with nits, thanks!
I'm in the middle of migrating an Android plugin implementation to Pigeon, and just ran into the need for this in order to preserve the existing error behavior :)
packages/pigeon/platform_tests/test_plugin/android/gradle/wrapper/gradle-wrapper.properties
Outdated
Show resolved
Hide resolved
Passes local Android integration tests |
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.
Thank you for putting this all together! Really great work here.
[pigeon] Standardize host api error handling
GeneratedApi.FlutterError
exception for passing custom error parameters (code, message, details).FlutterError
exception for passing custom error parameters (code, message, details).errorClassName
option inKotlinOptions
for custom error class names.FlutterError
handling integration tests for all platforms.Fixes flutter/flutter#120861
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.