fix(back-end): file error handling
All checks were successful
Build, Test and Deploy / test-backend (push) Successful in 34s
Build, Test and Deploy / build-and-push (push) Successful in 32s
Build, Test and Deploy / deploy (push) Successful in 6s

This commit is contained in:
2026-02-16 14:54:57 +01:00
parent 4aa3f6adf1
commit 6216d9a723
2 changed files with 21 additions and 17 deletions

View File

@@ -85,22 +85,7 @@ public class SlicerService {
logger.info("Executing Slicer: " + String.join(" ", command));
ProcessBuilder pb = new ProcessBuilder(command);
pb.directory(tempDir.toFile());
pb.environment().put("HOME", "/tmp");
pb.environment().put("QT_QPA_PLATFORM", "offscreen");
Process process = pb.start();
if (!process.waitFor(5, TimeUnit.MINUTES)) {
process.destroy();
throw new IOException("Slicer timeout");
}
if (process.exitValue() != 0) {
String out = new String(process.getInputStream().readAllBytes());
String err = new String(process.getErrorStream().readAllBytes());
throw new IOException("Slicer failed with exit code " + process.exitValue() + "\nERR: " + err + "\nOUT: " + out);
}
runSlicerCommand(command, tempDir);
// Find any .gcode file
try (Stream<Path> s = Files.list(tempDir)) {
@@ -114,4 +99,23 @@ public class SlicerService {
throw new IOException(e);
}
}
protected void runSlicerCommand(List<String> command, Path tempDir) throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder(command);
pb.directory(tempDir.toFile());
pb.environment().put("HOME", "/tmp");
pb.environment().put("QT_QPA_PLATFORM", "offscreen");
Process process = pb.start();
if (!process.waitFor(5, TimeUnit.MINUTES)) {
process.destroy();
throw new IOException("Slicer timeout");
}
if (process.exitValue() != 0) {
String out = new String(process.getInputStream().readAllBytes());
String err = new String(process.getErrorStream().readAllBytes());
throw new IOException("Slicer failed with exit code " + process.exitValue() + "\nERR: " + err + "\nOUT: " + out);
}
}
}

View File

@@ -49,7 +49,7 @@ class SlicerServiceTest {
// Subclass to override runSlicerCommand
slicerService = new SlicerService("orca-slicer", profileManager, gCodeParser, mapper) {
@Override
protected void runSlicerCommand(List<String> command, Path tempDir) throws IOException {
protected void runSlicerCommand(List<String> command, Path tempDir) throws IOException, InterruptedException {
lastCommand = command;
lastTempDir = tempDir;
// Don't run actual process.