File tree Expand file tree Collapse file tree
spring-shell-core/src/main/java/org/springframework/shell/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323import org .apache .commons .logging .LogFactory ;
2424
2525import org .springframework .shell .core .command .CommandContext ;
26+ import org .springframework .shell .core .command .CommandExecutionException ;
2627import org .springframework .shell .core .command .CommandExecutor ;
2728import org .springframework .shell .core .command .CommandParser ;
2829import org .springframework .shell .core .command .CommandRegistry ;
@@ -137,7 +138,8 @@ private void executeScript(InputProvider inputProvider) {
137138 if (ExitStatus .OK .code () != exitStatus .code ()) { // business error
138139 log .error ("Command " + parsedInput .commandName () + " returned an error: " + exitStatus .description ()
139140 + ". Skipping next commands in the script" );
140- break ;
141+ throw new CommandExecutionException ("Unable to execute command " + parsedInput .commandName () + ": "
142+ + exitStatus .description () + ". Skipping next commands in the script" );
141143 }
142144 }
143145 }
@@ -156,6 +158,8 @@ private void executeCommand(String primaryCommand) {
156158 ExitStatus exitStatus = this .commandExecutor .execute (commandContext );
157159 if (ExitStatus .OK .code () != exitStatus .code ()) {
158160 log .error ("Command " + parsedInput .commandName () + " returned an error: " + exitStatus .description ());
161+ throw new CommandExecutionException (
162+ "Unable to execute command " + primaryCommand + ": " + exitStatus .description (), exitStatus .code ());
159163 }
160164 }
161165
Original file line number Diff line number Diff line change 2424 */
2525public class CommandExecutionException extends RuntimeException {
2626
27+ private int exitCode = ExitStatus .EXECUTION_ERROR .code ();
28+
29+ /**
30+ * Create a new {@code CommandExecutionException} with the given message.
31+ * @param message the detail message
32+ */
2733 public CommandExecutionException (String message ) {
2834 super (message );
2935 }
3036
37+ /**
38+ * Create a new {@code CommandExecutionException} with the given message and exit
39+ * code.
40+ * @param message the detail message
41+ * @param exitCode the exit code associated with this exception
42+ * @since 4.0.2
43+ */
44+ public CommandExecutionException (String message , int exitCode ) {
45+ super (message );
46+ this .exitCode = exitCode ;
47+ }
48+
49+ /**
50+ * Create a new {@code CommandExecutionException} with the given message and cause.
51+ * @param message the detail message
52+ * @param cause the cause
53+ */
3154 public CommandExecutionException (String message , Throwable cause ) {
3255 super (message , cause );
3356 }
3457
58+ /**
59+ * Return the exit code associated with this exception.
60+ * @return the exit code
61+ * @since 4.0.2
62+ */
63+ public int getExitCode () {
64+ return this .exitCode ;
65+ }
66+
3567}
You can’t perform that action at this time.
0 commit comments