fix(back-end): file error handling
This commit is contained in:
@@ -85,22 +85,7 @@ public class SlicerService {
|
|||||||
|
|
||||||
logger.info("Executing Slicer: " + String.join(" ", command));
|
logger.info("Executing Slicer: " + String.join(" ", command));
|
||||||
|
|
||||||
ProcessBuilder pb = new ProcessBuilder(command);
|
runSlicerCommand(command, tempDir);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find any .gcode file
|
// Find any .gcode file
|
||||||
try (Stream<Path> s = Files.list(tempDir)) {
|
try (Stream<Path> s = Files.list(tempDir)) {
|
||||||
@@ -114,4 +99,23 @@ public class SlicerService {
|
|||||||
throw new IOException(e);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class SlicerServiceTest {
|
|||||||
// Subclass to override runSlicerCommand
|
// Subclass to override runSlicerCommand
|
||||||
slicerService = new SlicerService("orca-slicer", profileManager, gCodeParser, mapper) {
|
slicerService = new SlicerService("orca-slicer", profileManager, gCodeParser, mapper) {
|
||||||
@Override
|
@Override
|
||||||
protected void runSlicerCommand(List<String> command, Path tempDir) throws IOException {
|
protected void runSlicerCommand(List<String> command, Path tempDir) throws IOException, InterruptedException {
|
||||||
lastCommand = command;
|
lastCommand = command;
|
||||||
lastTempDir = tempDir;
|
lastTempDir = tempDir;
|
||||||
// Don't run actual process.
|
// Don't run actual process.
|
||||||
|
|||||||
Reference in New Issue
Block a user