{"record":{"id":"7393573db5b51413","repo":"SubtitleEdit/subtitleedit","slug":"failed-to-start-yt-dlp","errorCode":null,"errorMessage":"Failed to start yt-dlp","messagePattern":"Failed to start yt-dlp","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/ui/Logic/Download/YtDlpDownloadService.cs","lineNumber":296,"sourceCode":"            }\n\n            ReportLine(e.Data);\n        };\n\n        process.ErrorDataReceived += (_, e) =>\n        {\n            if (e.Data is null)\n            {\n                return;\n            }\n\n            stderrBuffer.AppendLine(e.Data);\n            ReportLine(e.Data);\n        };\n\n        if (!process.Start())\n        {\n            throw new InvalidOperationException(\"Failed to start yt-dlp\");\n        }\n\n        process.BeginOutputReadLine();\n        process.BeginErrorReadLine();\n\n        try\n        {\n            await process.WaitForExitAsync(cancellationToken);\n        }\n        catch (OperationCanceledException)\n        {\n            TryKillProcess(process);\n            throw;\n        }\n\n        if (process.ExitCode != 0)\n        {\n            var details = stderrBuffer.ToString().Trim();","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/ui/Logic/Download/YtDlpDownloadService.cs#L278-L314","documentation":"Thrown by DownloadVideo when Process.Start() returns false on the yt-dlp process. Start() returns false (rather than throwing) when the process is already running with the same path in some edge cases, or when the StartInfo is malformed such that the runtime declines to launch. The binary existence is checked separately (error 370), so reaching here means the file exists but would not start.","triggerScenarios":"process.Start() returns false for the yt-dlp binary — typically a StartInfo problem (FileName empty/malformed, UseShellExecute conflict with redirection), a permissions issue that does not throw, or the binary present but not executable (no +x on Linux).","commonSituations":"On Linux the downloaded yt-dlp lacks the execute bit; on any OS a corrupted/partial binary that the OS refuses to exec; or a StartInfo misconfiguration in a fork.","solutions":["On Linux/macOS ensure the yt-dlp binary is chmod +x (the downloader should set it; verify it did).","Re-run DownloadYtDlp to replace a possibly corrupted binary.","Inspect process.StartInfo — FileName must equal GetFullFileName() and UseShellExecute must be false with redirection enabled.","Manually run the yt-dlp binary from a shell to see the OS-level error (exec format error, permission denied)."],"exampleFix":"// before\nif (!process.Start()) throw new InvalidOperationException(\"Failed to start yt-dlp\");\n\n// after: set the exec bit on Unix before starting, and include the OS error\nif (!OperatingSystem.IsWindows())\n{\n    try { File.SetUnixPermissionMode(GetFullFileName(), UnixFileMode.UserExecute | UnixFileMode.UserRead); } catch { }\n}\nif (!process.Start())\n    throw new InvalidOperationException($\"Failed to start yt-dlp at {GetFullFileName()}\");","handlingStrategy":"try-catch","validationCode":"if (!OperatingSystem.IsWindows())\n    try { File.SetUnixPermissionMode(YtDlpDownloadService.GetFullFileName(), UnixFileMode.UserExecute | UnixFileMode.UserRead); } catch { }","typeGuard":null,"tryCatchPattern":"try { await svc.DownloadVideo(url, outPath, false, progress, ct); }\ncatch (InvalidOperationException ex) when (ex.Message == \"Failed to start yt-dlp\")\n{ /* re-download to repair the binary, then retry */ await svc.DownloadYtDlp(progress, ct); }","preventionTips":["Ensure the yt-dlp binary has the execute bit on Unix before launching.","Re-run DownloadYtDlp if the binary is suspected corrupt."],"tags":["yt-dlp","process","execution","permissions"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}