From 9cf30ef7d2bbfa9dfa8a87745f96224e0dfdc3e0 Mon Sep 17 00:00:00 2001 From: Emmanuel Bigeon Date: Sat, 8 Jun 2019 10:55:35 -0400 Subject: [PATCH] #4 #5 Update exception of script command Signed-off-by: Emmanuel Bigeon --- .../bigeon/gclc/command/base/ScriptExecution.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gclc/src/main/java/net/bigeon/gclc/command/base/ScriptExecution.java b/gclc/src/main/java/net/bigeon/gclc/command/base/ScriptExecution.java index cb0427e..2b27ffa 100644 --- a/gclc/src/main/java/net/bigeon/gclc/command/base/ScriptExecution.java +++ b/gclc/src/main/java/net/bigeon/gclc/command/base/ScriptExecution.java @@ -139,7 +139,7 @@ public final class ScriptExecution extends Command { try (InputStreamReader fReader = new InputStreamReader( Files.newInputStream(Paths.get(scriptFile)), charset); BufferedReader reader = new BufferedReader(fReader)) { - String[] emptyArray = new String[0]; + final String[] emptyArray = new String[0]; while ((cmd = reader.readLine()) != null) { lineNo++; final String cmdLine = readCommandLine(cmd, params); @@ -237,10 +237,16 @@ public final class ScriptExecution extends Command { * @return the exception to actually throw */ private static CommandRunException manageRunException(final CommandRunException e, final int lineNo) { + final StringBuilder builder = new StringBuilder(e.getLocalizedMessage()); + int index = builder.indexOf("\n"); + while (index > 0) { + builder.insert(index + 1, " "); + index = builder.indexOf("\n", index + 1); + } return new CommandRunException(CommandRunExceptionType.EXECUTION, MessageFormat.format( - "The script could not complete due to command failure at line {0} ({1})", //$NON-NLS-1$ - Integer.valueOf(lineNo), e.getLocalizedMessage()), + "The script could not complete due to command failure at line {0}\n {1})", //$NON-NLS-1$ + Integer.valueOf(lineNo + 1), builder.toString()), e); }