Improve ffprobe exceptions

This commit is contained in:
Malte Rosenbjerg 2021-07-16 01:02:38 +02:00
parent d3193827ac
commit 27fb37700c
5 changed files with 39 additions and 5 deletions

View file

@ -0,0 +1,11 @@
using System;
namespace FFMpegCore.Exceptions
{
public class FFProbeException : Exception
{
public FFProbeException(string message, Exception? inner = null) : base(message, inner)
{
}
}
}

View file

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
namespace FFMpegCore.Exceptions
{
public class FFProbeProcessException : FFProbeException
{
public IReadOnlyCollection<string> ProcessErrors { get; }
public FFProbeProcessException(string message, IReadOnlyCollection<string> processErrors, Exception? inner = null) : base(message, inner)
{
ProcessErrors = processErrors;
}
}
}

View file

@ -0,0 +1,9 @@
namespace FFMpegCore.Exceptions
{
public class FormatNullException : FFProbeException
{
public FormatNullException() : base("Format not specified")
{
}
}
}

View file

@ -93,7 +93,7 @@ public static async Task<IMediaAnalysis> AnalyseAsync(Stream stream, int outputC
}
var exitCode = await task.ConfigureAwait(false);
if (exitCode != 0)
throw new FFMpegException(FFMpegExceptionType.Process, $"FFProbe process returned exit status {exitCode}", null, string.Join("\n", instance.ErrorData));
throw new FFProbeProcessException($"ffprobe exited with non-zero exit-code ({exitCode} - {string.Join("\n", instance.ErrorData)})", instance.ErrorData);
pipeArgument.Post();
return ParseOutput(instance);
@ -108,7 +108,7 @@ private static IMediaAnalysis ParseOutput(Instance instance)
});
if (ffprobeAnalysis?.Format == null)
throw new Exception();
throw new FormatNullException();
return new MediaAnalysis(ffprobeAnalysis);
}
@ -123,8 +123,7 @@ private static Instance PrepareInstance(string filePath, int outputCapacity, FFO
StandardOutputEncoding = ffOptions.Encoding,
StandardErrorEncoding = ffOptions.Encoding
};
var instance = new Instance(startInfo)
{ DataBufferCapacity = outputCapacity };
var instance = new Instance(startInfo) { DataBufferCapacity = outputCapacity };
return instance;
}
}

View file

@ -30,7 +30,7 @@ public static void VerifyFFProbeExists(FFOptions ffMpegOptions)
var (exitCode, _) = Instance.Finish(GlobalFFOptions.GetFFProbeBinaryPath(ffMpegOptions), "-version");
_ffprobeVerified = exitCode == 0;
if (!_ffprobeVerified)
throw new FFMpegException(FFMpegExceptionType.Operation, "ffprobe was not found on your system");
throw new FFProbeException("ffprobe was not found on your system");
}
}
}