mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Merge pull request #51540 from xxxxxxjun
Closes gh-51540 * pr/51540: Print a simple error message when a jarmode tools command fails
This commit is contained in:
+5
@@ -22,11 +22,13 @@ import java.util.List;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.boot.loader.jarmode.JarMode;
|
||||
import org.springframework.boot.loader.jarmode.JarModeErrorException;
|
||||
|
||||
/**
|
||||
* {@link JarMode} providing {@code "tools"} support.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @author Hyeongjun Cho
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public class ToolsJarMode implements JarMode {
|
||||
@@ -54,6 +56,9 @@ public class ToolsJarMode implements JarMode {
|
||||
try {
|
||||
new Runner(this.out, this.context, getCommands(this.context)).run(args);
|
||||
}
|
||||
catch (JarModeErrorException ex) {
|
||||
throw ex;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
|
||||
+9
@@ -21,12 +21,16 @@ import java.io.IOException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.loader.jarmode.JarModeErrorException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests for {@link ToolsJarMode}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @author Hyeongjun Cho
|
||||
*/
|
||||
class ToolsJarModeTests extends AbstractJarModeTests {
|
||||
|
||||
@@ -95,6 +99,11 @@ class ToolsJarModeTests extends AbstractJarModeTests {
|
||||
assertThat(this.out).hasSameContentAsResource("tools-error-option-missing-value-output.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
void commandFailureIsThrownAsJarModeErrorException() {
|
||||
assertThatExceptionOfType(JarModeErrorException.class).isThrownBy(() -> run("list-layers"));
|
||||
}
|
||||
|
||||
private void run(String... args) {
|
||||
this.mode.run("tools", args);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user