Skip to content

Commit 9bea1c7

Browse files
ruromeroclaude
andcommitted
fix(image): gracefully handle missing Docker/Podman engine
ImageUtils.hostInfo() now returns an empty string instead of throwing RuntimeException when the container engine binary is missing (IOException) or returns error output. This allows callers to fall back gracefully rather than crashing when neither Docker nor Podman is installed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7d20efe commit 9bea1c7

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/main/java/io/github/guacsec/trustifyda/image/ImageUtils.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,18 @@ static String hostInfo(String engine, String info) {
281281
var exec = Operations.getCustomPathOrElse(engine);
282282
var cmd = new String[] {exec, "info"};
283283

284-
var output = Operations.runProcessGetFullOutput(null, cmd, null);
284+
Operations.ProcessExecOutput output;
285+
try {
286+
output = Operations.runProcessGetFullOutput(null, cmd, null);
287+
} catch (RuntimeException e) {
288+
if (e.getCause() instanceof IOException) {
289+
return "";
290+
}
291+
throw e;
292+
}
285293
if (output.getOutput().isEmpty()
286294
&& (!output.getError().isEmpty() || output.getExitCode() != 0)) {
287-
throw new RuntimeException(output.getError());
295+
return "";
288296
}
289297

290298
return output

src/test/java/io/github/guacsec/trustifyda/image/ImageUtilsTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import static org.assertj.core.api.Assertions.assertThat;
2828
import static org.junit.jupiter.api.Assertions.assertEquals;
2929
import static org.junit.jupiter.api.Assertions.assertNull;
30-
import static org.junit.jupiter.api.Assertions.assertThrows;
3130
import static org.junit.jupiter.api.Assertions.assertTrue;
3231
import static org.mockito.AdditionalMatchers.aryEq;
3332
import static org.mockito.ArgumentMatchers.any;
@@ -549,9 +548,8 @@ void test_host_info_no_docker_path() {
549548
isNull(), aryEq(new String[] {"docker", "info"}), isNull()))
550549
.thenReturn(output);
551550

552-
var exception =
553-
assertThrows(RuntimeException.class, () -> ImageUtils.hostInfo("docker", "info"));
554-
assertEquals("test-error", exception.getMessage());
551+
var result = ImageUtils.hostInfo("docker", "info");
552+
assertEquals("", result);
555553
}
556554
}
557555

0 commit comments

Comments
 (0)