Skip to content

Errors and Edge Cases

m4bwav edited this page Oct 1, 2026 · 1 revision

Every exception and message TrailerClipper 2.0.0 gives, with the input that causes it. The library throws; tclipper turns the same exceptions into a line on stderr and exit code 1 (Commands). Outputs below are from .NET 10 on Windows unless a runtime is named; throws lines show the exception's full type name and message as the verification program printed them.

Situation What happens
path does not exist FileNotFoundException
empty path to RemoveIntros or RemoveIntrosAndTrailers ArgumentOutOfRangeException (parameter path)
null options ArgumentNullException (parameter options)
negative trailer, or negative intro with RemoveIntro ArgumentOutOfRangeException, before any file is touched
negative intro to RemoveIntros ArgumentOutOfRangeException (parameter introLenghtInMilliseconds)
intro plus trailer at least the file's length the file is skipped, with a console line
extension not in the list the file is skipped silently
ffmpeg not found ToolNotFoundException (an InvalidOperationException), nothing clipped
ffprobe cannot read a file, or ffmpeg cannot write its copy the other files are clipped, then InvalidOperationException
file name with a double quote InvalidOperationException, collected like the line above
settings file missing, empty, null or not JSON InvalidOperationException or JsonException

Paths

new TrailerClipper().RemoveTrailers("Missing", 2000m);
throws System.IO.FileNotFoundException: File or directory at: Missing does not exist, nothing to clip.

The exception's FileName is the path. Every method checks the path this way; 1.1.0 did nothing for a missing path (Versions and upgrading).

new TrailerClipper().RemoveIntros("", 1500m);
throws System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'path')

Lengths

new TrailerClipper().RemoveTrailers("Episodes", -1000m);
throws System.ArgumentOutOfRangeException: Trailer length must not be negative: -1000 (Parameter 'options')
new TrailerClipper().RemoveIntros("Episodes", -1m);
throws System.ArgumentOutOfRangeException: Intro length must be greater than zero, otherwise there is nothing to clip (Parameter 'introLenghtInMilliseconds')

That message says "greater than zero", but zero is accepted (it removes nothing); only a negative intro is refused. The parameter name keeps 1.1.0's spelling. Nothing was written in either case.

Argument errors

On .NET Framework 4.8 these messages put the parameter on its own line, as .NET Framework always does:

throws System.ArgumentOutOfRangeException: Trailer length must not be negative: -1000
Parameter name: options
throws System.ArgumentOutOfRangeException: Intro length must be greater than zero, otherwise there is nothing to clip
Parameter name: introLenghtInMilliseconds

.NET 8 printed the same as .NET 10. The null case:

new TrailerClipper().RemoveTrailers((TrailerClipperOptions)null);
throws System.ArgumentNullException: Value cannot be null. (Parameter 'options')

ffmpeg not found

When FFmpegDirectory names a folder without ffmpeg, or nothing is found anywhere (Configuration):

var clipper = new TrailerClipper();
clipper.RemoveTrailers(new TrailerClipperOptions("Episodes", 2000m) { FFmpegDirectory = "NoFfmpeg" });
throws TrailerClipperLib.ToolNotFoundException: ffmpeg and ffprobe were not found. Install ffmpeg (Windows: winget install --id Gyan.FFmpeg -e; macOS: brew install ffmpeg; Linux: sudo apt install ffmpeg or sudo dnf install ffmpeg), or run 'tclipper --install-ffmpeg', or point TrailerClipperOptions.FFmpegDirectory or the TRAILERCLIPPER_FFMPEG environment variable at the folder that holds them.

The message is FFmpegLocator.InstallHint. It is thrown at the first media file, so nothing is clipped, and it is never collected with other failures. A folder with no media files needs no ffmpeg and throws nothing.

Files ffmpeg cannot read or write

A file ffprobe cannot read does not stop the batch. Broken holds a good ep3.wav and a text file named bad.mp3:

new TrailerClipper().RemoveTrailers("Broken", 2000m);
Starting on file: Broken\ep3.wav
Finished on trimming file, output: <cwd>\Broken\clipped\ep3.wav
throws System.InvalidOperationException: ffprobe could not read 'Broken\bad.mp3': ffprobe exited with non-zero exit-code (1 - [mp3 @ <address>] Failed to find two consecutive MPEG audio frames. | Broken\bad.mp3: Invalid data found when processing input)

The WAV copy was written; the last line is the exception. The message ends with ffmpeg's last lines joined by |; <address> stands for a memory address that changes on every run. With two or more failures the exception says how many and joins their messages with /, and its InnerException is an AggregateException holding each one (Recipes):

throws System.InvalidOperationException: 2 files could not be clipped: ffprobe could not read 'Broken2\bad.mp3': ffprobe exited with non-zero exit-code (1 - [mp3 @ <address>] Failed to find two consecutive MPEG audio frames. | Broken2\bad.mp3: Invalid data found when processing input) / ffprobe could not read 'Broken2\bad.wav': ffprobe exited with non-zero exit-code (1 - Broken2\bad.wav: Invalid data found when processing input)

With ProcessEveryFile, a file with no extension is read but cannot be written, because ffmpeg picks the output format from the extension:

new TrailerClipper().RemoveTrailers(new TrailerClipperOptions("NoExt", 2000m) { ProcessEveryFile = true });
Starting on file: NoExt\audio
throws System.InvalidOperationException: ffmpeg could not clip 'NoExt\audio': [out#0 @ <address>] Error initializing the muxer for <cwd>\NoExt\clipped\audio: Invalid argument | Error opening output file <cwd>\NoExt\clipped\audio. | Error opening output files: Invalid argument)

A failed file's original is never deleted, even with DeleteOriginalFiles.

A double quote in a file name

FFMpegCore passes paths to ffmpeg in double quotes without escaping them, so a " in a name could pass options to ffmpeg. Such files are refused. Windows does not allow the character in names; on Linux, with a file named say "hi".wav:

new TrailerClipper().RemoveTrailers("Quote", 2000m);
throws System.InvalidOperationException: File names that contain a double quote are not supported: 'Quote/say "hi".wav'

It is collected like the failures above, so the other files in the folder are still clipped.

Settings files

new TrailerClipper().RemoveTrailersWithOptionsFile("missing.json");
throws System.InvalidOperationException: Cannot find config file: missing.json

A file holding null, an empty file, and one in JavaScript style with single quotes:

File.WriteAllText("null.json", "null");
File.WriteAllText("empty.json", "");
File.WriteAllText("quotes.json", "[{'InputPath':'Episodes'}]");
foreach (var file in new[] { "null.json", "empty.json", "quotes.json" })
{
    try
    {
        new TrailerClipper().RemoveTrailersWithOptionsFile(file);
    }
    catch (Exception e)
    {
        Console.WriteLine(file + ": " + e.GetType().Name + ": " + e.Message);
    }
}
null.json: InvalidOperationException: Config file holds no clipping settings: null.json
empty.json: JsonException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
quotes.json: JsonException: ''' is an invalid start of a property name. Expected a '"'. Path: $[0] | LineNumber: 0 | BytePositionInLine: 2.

1.1.0 accepted single quotes and unquoted property names, and threw NullReferenceException for the first two (CHANGELOG, E11). tclipper prints a JsonException as The config file is not valid JSON: followed by the message.

With no path and no TrailerClipperConfig.json in the current folder, nothing is thrown:

new TrailerClipper().RemoveTrailersWithOptionsFile();
No parameters and no config file available, use -h for help

And CreateDefaultSampleConfig() never overwrites:

var clipper = new TrailerClipper();
clipper.CreateDefaultSampleConfig();
clipper.CreateDefaultSampleConfig();
Cannot create a sample config file because a file with the name: TrailerClipperConfig.json, already exists

Command-line arguments

ClipperCommandLineInterpreter.ParseCommandLineArgs never throws for bad arguments: it prints a message and returns null. The messages are on Commands.

Clone this wiki locally