Skip to content

Commit

Permalink
Collect diagnostic information if failed to start a process. (kokorin…
Browse files Browse the repository at this point in the history
  • Loading branch information
kokorin authored Oct 19, 2021
1 parent 752a018 commit 6b026e6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.Closeable;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -145,10 +146,10 @@ public synchronized T execute() {

return interactWithProcess(process);
} catch (IOException e) {
collectDebugInformation();
throw new JaffreeException("Failed to start process.", e);
} finally {
if (process != null) {
// TODO on Windows process sometimes doesn't stop and keeps running
process.destroy();
// Process must be destroyed before closing streams, can't use
// try-with-resources, as resources are closing when leaving try block,
Expand Down Expand Up @@ -320,4 +321,17 @@ private static void waitForExecutorToStop(final Executor executor, final long ti
Thread.sleep(100);
} while (executor.isRunning());
}

private static void collectDebugInformation() {
try {
LOGGER.warn("Collecting debug information");
LOGGER.warn("User: {}", System.getProperty("user.name"));
LOGGER.warn("OS: {}", System.getProperty("os.name"));
LOGGER.warn("User Dir: {}", System.getProperty("user.dir"));
LOGGER.warn("Work Dir: {}", Paths.get(".").toAbsolutePath());
LOGGER.warn("PATH: {}", System.getenv("PATH"));
} catch (Exception e) {
LOGGER.warn("Failure while collecting debug information.", e);
}
}
}
10 changes: 10 additions & 0 deletions src/test/java/com/github/kokorin/jaffree/ffmpeg/FFmpegTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.github.kokorin.jaffree.ffprobe.FFprobe;
import com.github.kokorin.jaffree.ffprobe.FFprobeResult;
import com.github.kokorin.jaffree.ffprobe.Stream;
import com.github.kokorin.jaffree.process.ProcessHandler;
import com.github.kokorin.jaffree.process.ProcessHelper;
import org.hamcrest.core.AllOf;
import org.hamcrest.core.StringContains;
Expand Down Expand Up @@ -906,4 +907,13 @@ public void testAsyncToCompletableFuture() throws Exception {

assertEquals(2, probeResult.getStreams().size());
}

@Test
@Ignore("Should be ran manually")
public void testNoFFmpegExecutableFound() {
FFmpeg.atPath(Paths.get("."))
.addInput(UrlInput.fromPath(Artifacts.VIDEO_MP4))
.addOutput(new NullOutput())
.execute();
}
}

0 comments on commit 6b026e6

Please sign in to comment.