Compare commits

..

5 commits

Author SHA1 Message Date
Sergey Nechaev
524803c88b
Merge 65cbc5552c into 2f06ec99f3 2025-10-25 16:08:28 +02:00
Sergey Nechaev
65cbc5552c Update the ThrowIfExitCodeNotZero() to check the exit code before handling cancellation.
This preserves the original semantics and contract (throw only if the ffprobe exits with a non-zero code).
2025-10-24 18:06:55 +02:00
Sergey Nechaev
8f9930ad2a Additional test to verify that FFProbeHelper still throws FFMpegException when FFProbe exits with non-zero code and no cancellation was requested.
Ref.: #594
2025-10-22 21:24:32 +02:00
Sergey Nechaev
c3e80a7af6 FFProbe: Do not throw FFMpegException if cancellation was requested.
Throw OperationCancelledException in this case to provide more uniform and expected behavior.

Fixes #594
2025-10-22 20:44:50 +02:00
Sergey Nechaev
5f906af57f Add test to verify unexpected exception on FFProbe operations cancellation.
Ref.: #594
2025-10-22 20:44:50 +02:00

View file

@ -84,8 +84,7 @@ public static class FFProbe
var instance = PrepareStreamAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments); var instance = PrepareStreamAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments);
var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false); var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested(); ThrowIfExitCodeNotZero(result, cancellationToken);
ThrowIfExitCodeNotZero(result);
return ParseOutput(result); return ParseOutput(result);
} }
@ -124,8 +123,7 @@ public static class FFProbe
{ {
var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments); var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments);
var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false); var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested(); ThrowIfExitCodeNotZero(result, cancellationToken);
ThrowIfExitCodeNotZero(result);
return ParseOutput(result); return ParseOutput(result);
} }
@ -152,8 +150,7 @@ public static class FFProbe
} }
var result = await task.ConfigureAwait(false); var result = await task.ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested(); ThrowIfExitCodeNotZero(result, cancellationToken);
ThrowIfExitCodeNotZero(result);
pipeArgument.Post(); pipeArgument.Post();
return ParseOutput(result); return ParseOutput(result);
@ -215,10 +212,13 @@ public static class FFProbe
} }
} }
private static void ThrowIfExitCodeNotZero(IProcessResult result) private static void ThrowIfExitCodeNotZero(IProcessResult result, CancellationToken cancellationToken = default)
{ {
if (result.ExitCode != 0) if (result.ExitCode != 0)
{ {
// if cancellation requested, then we are not interested in the exit code, just throw the cancellation exception
// to get consistent and expected behavior.
cancellationToken.ThrowIfCancellationRequested();
var message = $"ffprobe exited with non-zero exit-code ({result.ExitCode} - {string.Join("\n", result.ErrorData)})"; var message = $"ffprobe exited with non-zero exit-code ({result.ExitCode} - {string.Join("\n", result.ErrorData)})";
throw new FFMpegException(FFMpegExceptionType.Process, message, null, string.Join("\n", result.ErrorData)); throw new FFMpegException(FFMpegExceptionType.Process, message, null, string.Join("\n", result.ErrorData));
} }