Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap Instances exception for expected behaviour #412

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions FFMpegCore.Test/FFMpegArgumentProcessorTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Reflection;
using FFMpegCore.Arguments;
using FFMpegCore.Exceptions;
using FFMpegCore.Helpers;
using FluentAssertions;
using Instances.Exceptions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FFMpegCore.Test
Expand Down Expand Up @@ -99,5 +102,12 @@
var arg = new AudibleEncryptionKeyArgument("62689101");
arg.Text.Should().Be($"-activation_bytes 62689101");
}

[TestMethod]
public void Throws_FFMpegException_when_ffmpeg_not_found()
{
var exception = Assert.ThrowsException<FFMpegException>(() => FFMpegHelper.VerifyFFMpegExists(new FFOptions { BinaryFolder = "./folder/that/does/not/exist" }));

Check failure on line 109 in FFMpegCore.Test/FFMpegArgumentProcessorTest.cs

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Throws_FFMpegException_when_ffmpeg_not_found

Assert.ThrowsException failed. Expected exception type:<FFMpegCore.Exceptions.FFMpegException> but no exception was thrown.

Check failure on line 109 in FFMpegCore.Test/FFMpegArgumentProcessorTest.cs

View workflow job for this annotation

GitHub Actions / ci (macos-13)

Throws_FFMpegException_when_ffmpeg_not_found

Assert.ThrowsException failed. Expected exception type:<FFMpegCore.Exceptions.FFMpegException> but no exception was thrown.
Assert.IsInstanceOfType<InstanceFileNotFoundException>(exception.InnerException);
}
}
}
12 changes: 10 additions & 2 deletions FFMpegCore/Helpers/FFMpegHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,16 @@ public static void VerifyFFMpegExists(FFOptions ffMpegOptions)
return;
}

var result = Instance.Finish(GlobalFFOptions.GetFFMpegBinaryPath(ffMpegOptions), "-version");
_ffmpegVerified = result.ExitCode == 0;
try
{
var result = Instance.Finish(GlobalFFOptions.GetFFMpegBinaryPath(ffMpegOptions), "-version");
_ffmpegVerified = result.ExitCode == 0;
}
catch (Exception e)
{
throw new FFMpegException(FFMpegExceptionType.Operation, "ffmpeg was not found on your system", e);
}

if (!_ffmpegVerified)
{
throw new FFMpegException(FFMpegExceptionType.Operation, "ffmpeg was not found on your system");
Expand Down
Loading