Print a simple error message when a jarmode tools command fails

See gh-51540

Signed-off-by: Hyeongjun Cho <ryuu.public@gmail.com>
This commit is contained in:
Hyeongjun Cho
2026-09-02 16:17:49 +02:00
committed by Moritz Halbritter
parent 05bd7202ba
commit d92a75c66b
2 changed files with 14 additions and 0 deletions
@@ -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);
}
@@ -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);
}