Repository navigation
Add "error" method to the Result interface in Pigeon #83244
Description
Activity
- addedin triagePresently being triaged by the triage teamPresently being triaged by the triage teamp: pigeonrelated to pigeon messaging codegen toolrelated to pigeon messaging codegen toolc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityand removedin triagePresently being triaged by the triage teamPresently being triaged by the triage team
on May 24, 2021 /cc @gaaclarke
- addedP2Important issues not at the top of the work listImportant issues not at the top of the work list
on May 27, 2021 Yea, here is the caller of the callback:
{ BasicMessageChannel<Object> channel = new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.Api2Host.calculate", new StandardMessageCodec()); if (api != null) { channel.setMessageHandler((message, reply) -> { Map<String, Object> wrapped = new HashMap<>(); try { @SuppressWarnings("ConstantConditions") Value input = Value.fromMap((Map<String, Object>)message); api.calculate(input, result -> { wrapped.put("result", result.toMap()); reply.reply(wrapped); }); } catch (Error | RuntimeException exception) { wrapped.put("error", wrapError(exception)); reply.reply(wrapped); } }); } else { channel.setMessageHandler(null); } }We should have a way to fill in
wrapped.put("error", wrapError(exception))in response to the callback.As a workaround for now you can include an error in your pigeon class:
class QueryResult { String? error; String? result; } @HostApi() abstract class Api { @async QueryResult query(); }
+1.
We just ran into needing this as well. Would be nice to have.
+1
yes, I think this is needed.
Trying to have an object that represents an error doesn't work for me:
class ErrorClass { final int code; final String message; ErrorClass({required this.code, required this.message}); } class ResultType { final string someValue; ResultType({required this.someValue}); } class Reply { final ErrorClass? error; final ResultType? result; Reply({this.error, this.result}); }and returning something like error = null and result != null or vice versa from Java / Kotlin, throws a null reference exception stating that error is null but it should not be null when calling
error.toMap()for example.Attempt to invoke virtual method 'java.util.Map x.y.z.ErrorClass.toMap()' on a null object referenceany news?
Fixed in flutter/packages#460, It took a while because I didn't want to implement it until the testing framework for the java generator was improved.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.- locked as resolved and limited conversation to collaborators
on Sep 22, 2021 - addedpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.
on Jul 5, 2023
Use case
I'm using Pigeon to generate type-safe interop with native platforms.
In the case of
@asyncfunctions, it generates the following interface in JavaIt has no way to report an error.
My use case is to call some method on the Host, and in case of any error, I need to show an error popup on the Flutter side.
Proposal
I suggest adding
errormethod to the interface