diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/MethodChannel.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/MethodChannel.java index 8c0bdd68955..65ea2393d6c 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/MethodChannel.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/MethodChannel.java @@ -165,7 +165,9 @@ public final class MethodChannel { /** * Handles a successful result. * - * @param result The result, possibly null. + * @param result The result, possibly null. The result must be an Object type supported by the + * codec. For instance, if you are using StandardCodec (default), please see {@link + * StandardMessageCodec} documentation on what types are supported. */ @UiThread void success(@Nullable Object result); @@ -175,7 +177,9 @@ public final class MethodChannel { * * @param errorCode An error code String. * @param errorMessage A human-readable error message String, possibly null. - * @param errorDetails Error details, possibly null + * @param errorDetails Error details, possibly null. The details must be an Object type + * supported by the codec. For instance, if you are using StandardCodec (default), please + * see {@link StandardMessageCodec} documentation on what types are supported. */ @UiThread void error(String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails); diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/StandardMethodCodec.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/StandardMethodCodec.java index 329d5dd37d9..913001f5b2b 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/StandardMethodCodec.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/StandardMethodCodec.java @@ -5,6 +5,9 @@ package io.flutter.plugin.common; import io.flutter.plugin.common.StandardMessageCodec.ExposedByteArrayOutputStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.io.Writer; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -66,7 +69,11 @@ public final class StandardMethodCodec implements MethodCodec { stream.write(1); messageCodec.writeValue(stream, errorCode); messageCodec.writeValue(stream, errorMessage); - messageCodec.writeValue(stream, errorDetails); + if (errorDetails instanceof Throwable) { + messageCodec.writeValue(stream, getStackTrace((Throwable) errorDetails)); + } else { + messageCodec.writeValue(stream, errorDetails); + } final ByteBuffer buffer = ByteBuffer.allocateDirect(stream.size()); buffer.put(stream.buffer(), 0, stream.size()); return buffer; @@ -99,4 +106,10 @@ public final class StandardMethodCodec implements MethodCodec { } throw new IllegalArgumentException("Envelope corrupted"); } + + private static String getStackTrace(Throwable t) { + Writer result = new StringWriter(); + t.printStackTrace(new PrintWriter(result)); + return result.toString(); + } }