Skip to content

Commit

Permalink
Include Java stack trace in method channel invocations (flutter#11361)
Browse files Browse the repository at this point in the history
  • Loading branch information
amirh authored Aug 22, 2019
1 parent bb8e6e4 commit 0345967
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -36,6 +38,13 @@ public void invokeViewFocused(int viewId) {
channel.invokeMethod("viewFocused", viewId);
}

private static String detailedExceptionString(Exception exception) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
exception.printStackTrace(printWriter);
return stringWriter.toString();
}

private final MethodChannel.MethodCallHandler parsingHandler = new MethodChannel.MethodCallHandler() {
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
Expand Down Expand Up @@ -89,7 +98,7 @@ private void create(@NonNull MethodCall call, @NonNull MethodChannel.Result resu
} catch (IllegalStateException exception) {
result.error(
"error",
exception.getMessage(),
detailedExceptionString(exception),
null
);
}
Expand All @@ -103,7 +112,7 @@ private void dispose(@NonNull MethodCall call, @NonNull MethodChannel.Result res
} catch (IllegalStateException exception) {
result.error(
"error",
exception.getMessage(),
detailedExceptionString(exception),
null
);
}
Expand All @@ -129,7 +138,7 @@ public void run() {
} catch (IllegalStateException exception) {
result.error(
"error",
exception.getMessage(),
detailedExceptionString(exception),
null
);
}
Expand Down Expand Up @@ -161,7 +170,7 @@ private void touch(@NonNull MethodCall call, @NonNull MethodChannel.Result resul
} catch (IllegalStateException exception) {
result.error(
"error",
exception.getMessage(),
detailedExceptionString(exception),
null
);
}
Expand All @@ -181,7 +190,7 @@ private void setDirection(@NonNull MethodCall call, @NonNull MethodChannel.Resul
} catch (IllegalStateException exception) {
result.error(
"error",
exception.getMessage(),
detailedExceptionString(exception),
null
);
}
Expand All @@ -195,7 +204,7 @@ private void clearFocus(@NonNull MethodCall call, @NonNull MethodChannel.Result
} catch (IllegalStateException exception) {
result.error(
"error",
exception.getMessage(),
detailedExceptionString(exception),
null
);
}
Expand Down

0 comments on commit 0345967

Please sign in to comment.