From 6b026e60fb963ad96af00d5477169c7c01b1248c Mon Sep 17 00:00:00 2001 From: Denis Kokorin Date: Tue, 19 Oct 2021 09:02:43 +0300 Subject: [PATCH] Collect diagnostic information if failed to start a process. (#238) Fix #224. --- .../kokorin/jaffree/process/ProcessHandler.java | 16 +++++++++++++++- .../kokorin/jaffree/ffmpeg/FFmpegTest.java | 10 ++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/kokorin/jaffree/process/ProcessHandler.java b/src/main/java/com/github/kokorin/jaffree/process/ProcessHandler.java index f2808e86..9c7bc5ee 100644 --- a/src/main/java/com/github/kokorin/jaffree/process/ProcessHandler.java +++ b/src/main/java/com/github/kokorin/jaffree/process/ProcessHandler.java @@ -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; @@ -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, @@ -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); + } + } } diff --git a/src/test/java/com/github/kokorin/jaffree/ffmpeg/FFmpegTest.java b/src/test/java/com/github/kokorin/jaffree/ffmpeg/FFmpegTest.java index b73d610f..29f631d2 100644 --- a/src/test/java/com/github/kokorin/jaffree/ffmpeg/FFmpegTest.java +++ b/src/test/java/com/github/kokorin/jaffree/ffmpeg/FFmpegTest.java @@ -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; @@ -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(); + } }