Source:
<code>public void run(final ActionContext context) throws Exception { Connection connection = new Connection(config.host); try { try { connection.connect(); } catch (IOException e) { <START> throw new IOException(String.format("Attempt to connect to host %s failed", config.host)); <END> } String password = Strings.isNullOrEmpty(config.password) ? null : config.password; if (!connection.authenticateWithPublicKey(config.user, new File(config.privateKeyFile), password)) { throw new IOException(String.format("SSH authentication error when connecting to %s@%s on port %d", config.user, config.host, config.port)); } LOG.debug("Connection established with the host {}", config.host); Session session = connection.openSession(); try { session.execCommand(config.command); } catch (IOException e) { throw new IOException(String.format("Exception thrown while executing command: %s", e.getMessage())); } InputStream stdout = new StreamGobbler(session.getStdout()); BufferedReader outBuffer = new BufferedReader(new InputStreamReader(stdout, Charsets.UTF_8)); InputStream stderr = new StreamGobbler(session.getStderr()); BufferedReader errBuffer = new BufferedReader(new InputStreamReader(stderr, Charsets.UTF_8)); String out = CharStreams.toString(outBuffer); String err = CharStreams.toString(errBuffer); LOG.debug("Output: {}", out); LOG.error("Errors: {}", err); Integer exitCode = session.getExitStatus(); if (exitCode != null && exitCode > 0) { throw new IOException(String.format("Error: command finished with exit code: %d", exitCode)); } if (config.output != null) { context.getArguments().set(config.output, out.replaceAll("\\s+$", "")); } } finally { connection.close(); } }</code><technical_language>this surface _why_ connection failed</technical_language>

Target:
public void run(final ActionContext context) throws Exception { Connection connection = new Connection(config.host); try { connection.connect(); String password = Strings.isNullOrEmpty(config.password) ? null : config.password; if (!connection.authenticateWithPublicKey(config.user, new File(config.privateKeyFile), password)) { throw new IOException(String.format("SSH authentication error when connecting to %s@%s on port %d", config.user, config.host, config.port)); } LOG.debug("Connection established with the host {}", config.host); Session session = connection.openSession(); session.execCommand(config.command); InputStream stdout = new StreamGobbler(session.getStdout()); BufferedReader outBuffer = new BufferedReader(new InputStreamReader(stdout, Charsets.UTF_8)); InputStream stderr = new StreamGobbler(session.getStderr()); BufferedReader errBuffer = new BufferedReader(new InputStreamReader(stderr, Charsets.UTF_8)); String out = CharStreams.toString(outBuffer); String err = CharStreams.toString(errBuffer); LOG.debug("Output: {}", out); LOG.error("Errors: {}", err); Integer exitCode = session.getExitStatus(); if (exitCode != null && exitCode != 0) { throw new IOException(String.format("Error: command %s running on hostname %s finished with exit code: %d", config.command, config.host, exitCode)); } if (config.output != null) { out = out.endsWith("\n") ? out.substring(0, out.length() - 1) : out; context.getArguments().set(config.output, out); } } finally { connection.close(); } }