{"record":{"id":"410abc52edc7a9b4","repo":"subhra74/xdm","slug":"non-zero-error-code-from-youtube-dl","errorCode":null,"errorMessage":"Non-zero error code from youtube-dl: ","messagePattern":"Non-zero error code from youtube-dl: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/XDM/XDM.Core/YDLWrapper/YDLProcess.cs","lineNumber":112,"sourceCode":"                ydlProc.ErrorDataReceived += (a, b) =>\r\n                {\r\n                    if (b.Data != null)\r\n                    {\r\n                        Log.Debug(b.Data);\r\n                    }\r\n                };\r\n\r\n                ydlProc.BeginOutputReadLine();\r\n\r\n                ydlProc.WaitForExit();\r\n                fs.Close();\r\n\r\n                var exitCode = ydlProc.ExitCode;\r\n\r\n                if (ydlProc.ExitCode != 0)\r\n                {\r\n                    Log.Debug(\"Non-zero error code from youtube-dl: \" + ydlProc.ExitCode);\r\n                    throw new Exception(\"Non-zero error code from youtube-dl: \" + ydlProc.ExitCode);\r\n                }\r\n            }\r\n            finally\r\n            {\r\n                ydlProc?.Dispose();\r\n                ydlProc = null;\r\n            }\r\n        }\r\n\r\n        private static YtBinaryType GetYtBinaryType(string executableName)\r\n        {\r\n            if (executableName.StartsWith(\"yt-dlp\"))\r\n            {\r\n                return YtBinaryType.YtDlp;\r\n            }\r\n            return YtBinaryType.Yt;\r\n        }\r\n\r","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/subhra74/xdm/blob/1ca5a25aae007826c859c81bea494e7c102e1242/app/XDM/XDM.Core/YDLWrapper/YDLProcess.cs#L94-L130","documentation":"YDLProcess.Start runs an external youtube-dl/yt-dlp process and, after it exits, throws if the exit code is non-zero. youtube-dl uses non-zero exit codes to signal download/extraction failures (network errors, unsupported URL, HTTP 403/404, missing ffmpeg, etc.). The exception message includes the numeric exit code but not stderr — that is only written to the debug log.","triggerScenarios":"Any invocation of a ydl-based operation (download/info extraction via YDLProcess.Start) where the youtube-dl/yt-dlp process terminates with ExitCode != 0 — e.g. unsupported URL, HTTP errors fetching the video, ffmpeg missing for requested format merge, out-of-date extractor.","commonSituations":"Outdated youtube-dl facing a site layout change (exit code 1); requested format unavailable (exit 1); disk full or permission errors; ffmpeg not on PATH when merging formats (exit 1); site requires cookies/age verification.","solutions":["Read the debug log entry 'Non-zero error code from youtube-dl: <code>' and the captured process output to see the underlying yt-dlp error.","Update youtube-dl/yt-dlp to the latest version (most failures are stale extractors).","Verify ffmpeg/ffprobe are installed and on PATH if format merging/conversion was requested.","Test the same URL directly with yt-dlp on the command line to reproduce and see the full error text.","Retry with different format selection or pass cookies/user-agent if the site requires authentication."],"exampleFix":"// before\nydl.Start(); // throws generic Exception on failure\n\n// after\ntry\n{\n    ydl.Start();\n}\ncatch (Exception ex)\n{\n    Log.Debug(ex, \"ydl failed; check yt-dlp version and ffmpeg availability\");\n    throw;\n}","handlingStrategy":"try-catch","validationCode":"var which = TryRun(\"yt-dlp --version\");\nif (which == null) throw new Exception(\"yt-dlp not runnable\");","typeGuard":null,"tryCatchPattern":"try { ydlProc.Start(); }\ncatch (Exception ex) when (ex.Message.StartsWith(\"Non-zero error code from youtube-dl\"))\n{\n    Log.Error(ex, \"yt-dlp failed; update yt-dlp, verify ffmpeg on PATH, check the URL\");\n    throw;\n}","preventionTips":["Keep yt-dlp up to date (stale extractors are the top cause)","Test failing URLs directly on the yt-dlp CLI for full error output","Ensure ffmpeg/ffprobe are installed for merge operations","Capture and log stderr of the child process, not just the exit code"],"tags":["youtube-dl","external-process","exit-code","download"],"backgroundTag":"command-not-found","analyzedSha":"1ca5a25aae007826c859c81bea494e7c102e1242","analyzedAt":"2026-09-13T20:37:40.968Z","contentChangedAt":"2026-09-13T20:37:40.968Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}