Compare commits

..

6 commits

Author SHA1 Message Date
Sergey Nechaev
04dd56f2f4
Merge 67af2aa01d into 2f06ec99f3 2025-10-27 12:39:55 +00:00
Sergey Nechaev
67af2aa01d Move cancellation check outside of the ThrowIfExitCodeNotZero() and call it separately in all the async code paths. 2025-10-27 13:36:42 +01:00
Sergey Nechaev
560c791802 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-27 13:30:59 +01:00
Sergey Nechaev
e44611bd25 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-27 13:30:59 +01:00
Sergey Nechaev
b863f5d19e 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-27 13:30:59 +01:00
Sergey Nechaev
930d493b8c Add test to verify unexpected exception on FFProbe operations cancellation.
Ref.: #594
2025-10-27 13:30:59 +01:00

View file

@ -84,7 +84,8 @@ public static class FFProbe
var instance = PrepareStreamAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments);
var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false);
ThrowIfExitCodeNotZero(result, cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
ThrowIfExitCodeNotZero(result);
return ParseOutput(result);
}
@ -123,7 +124,8 @@ public static class FFProbe
{
var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments);
var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false);
ThrowIfExitCodeNotZero(result, cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
ThrowIfExitCodeNotZero(result);
return ParseOutput(result);
}
@ -150,7 +152,8 @@ public static class FFProbe
}
var result = await task.ConfigureAwait(false);
ThrowIfExitCodeNotZero(result, cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
ThrowIfExitCodeNotZero(result);
pipeArgument.Post();
return ParseOutput(result);
@ -212,13 +215,10 @@ public static class FFProbe
}
}
private static void ThrowIfExitCodeNotZero(IProcessResult result, CancellationToken cancellationToken = default)
private static void ThrowIfExitCodeNotZero(IProcessResult result)
{
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)})";
throw new FFMpegException(FFMpegExceptionType.Process, message, null, string.Join("\n", result.ErrorData));
}