From c1753247a6e178f241463a522788a5aa61443f44 Mon Sep 17 00:00:00 2001 From: Luis Madrigal <599908+Madrigal@users.noreply.github.com> Date: Fri, 27 Sep 2024 12:55:44 -0400 Subject: [PATCH] Print output when executing commands when exit code != 0 (#540) Print output when executing commands when exit code != 0 --- .../amazon/smithy/go/codegen/testutils/ExecuteCommand.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/testutils/ExecuteCommand.java b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/testutils/ExecuteCommand.java index 0ba5bba6..27e0b671 100644 --- a/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/testutils/ExecuteCommand.java +++ b/codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/testutils/ExecuteCommand.java @@ -59,6 +59,7 @@ public static void execute(File workingDir, String... command) throws Exception public void execute() throws Exception { int exitCode; Process child; + var output = new StringBuilder(); try { var cmdArray = new String[command.size()]; command.toArray(cmdArray); @@ -73,12 +74,16 @@ public void execute() throws Exception { InputStreamReader(child.getErrorStream(), Charset.defaultCharset())); String s; + output.append("stdout: "); while ((s = stdOut.readLine()) != null) { LOGGER.info(s); + output.append(s); } stdOut.close(); + output.append(" stderr: "); while ((s = stdErr.readLine()) != null) { LOGGER.warning(s); + output.append(s); } stdErr.close(); } catch (Exception e) { @@ -87,7 +92,7 @@ public void execute() throws Exception { if (exitCode != 0) { throw new Exception("Command existed with non-zero code, " + command - + ", status code: " + exitCode); + + ", status code: " + exitCode + " output: " + output); } }