FFProbe: Do not throw FFMpegException if cancellation was requested.

Throw OperationCancelledException in this case to provide more uniform and expected behavior.

Fixes #594
This commit is contained in:
Sergey Nechaev 2025-10-22 20:41:26 +02:00
parent 930d493b8c
commit b863f5d19e
2 changed files with 8 additions and 5 deletions

View file

@ -84,7 +84,7 @@ public static class FFProbe
var instance = PrepareStreamAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments);
var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false);
ThrowIfExitCodeNotZero(result);
ThrowIfExitCodeNotZero(result, cancellationToken);
return ParseOutput(result);
}
@ -123,7 +123,7 @@ public static class FFProbe
{
var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments);
var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false);
ThrowIfExitCodeNotZero(result);
ThrowIfExitCodeNotZero(result, cancellationToken);
return ParseOutput(result);
}
@ -150,7 +150,7 @@ public static class FFProbe
}
var result = await task.ConfigureAwait(false);
ThrowIfExitCodeNotZero(result);
ThrowIfExitCodeNotZero(result, cancellationToken);
pipeArgument.Post();
return ParseOutput(result);
@ -212,8 +212,11 @@ public static class FFProbe
}
}
private static void ThrowIfExitCodeNotZero(IProcessResult result)
private static void ThrowIfExitCodeNotZero(IProcessResult result, CancellationToken cancellationToken = default)
{
// 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();
if (result.ExitCode != 0)
{
var message = $"ffprobe exited with non-zero exit-code ({result.ExitCode} - {string.Join("\n", result.ErrorData)})";

View file

@ -13,6 +13,6 @@ public static class ProcessArgumentsExtensions
public static async Task<IProcessResult> StartAndWaitForExitAsync(this ProcessArguments processArguments, CancellationToken cancellationToken = default)
{
using var instance = processArguments.Start();
return await instance.WaitForExitAsync(cancellationToken);
return await instance.WaitForExitAsync(cancellationToken).ConfigureAwait(false);
}
}