You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add "error" method to the Result interface in Pigeon #83244
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 reference
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 -v and a minimal reproduction of the issue.
Activity
stuartmorgan-g commentedon May 27, 2021
/cc @gaaclarke
gaaclarke commentedon May 28, 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:
ajmalk commentedon Jul 17, 2021
+1.
We just ran into needing this as well. Would be nice to have.
AhmedNourJamalElDin commentedon Jul 17, 2021
+1
yes, I think this is needed.
Trying to have an object that represents an error doesn't work for me:
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.cenumi commentedon Sep 6, 2021
any news?
gaaclarke commentedon Sep 7, 2021
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.
github-actions commentedon Sep 22, 2021
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.