{"record":{"id":"231e3179b9f95d5b","repo":"ytdl-org/youtube-dl","slug":"playlist-start-must-be-positive","errorCode":null,"errorMessage":"Playlist start must be positive","messagePattern":"Playlist start must be positive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"youtube_dl/__init__.py","lineNumber":204,"sourceCode":"            except (TypeError, ValueError):\n                parser.error('invalid retry count specified')\n        return parsed_retries\n    if opts.retries is not None:\n        opts.retries = parse_retries(opts.retries)\n    if opts.fragment_retries is not None:\n        opts.fragment_retries = parse_retries(opts.fragment_retries)\n    if opts.buffersize is not None:\n        numeric_buffersize = FileDownloader.parse_bytes(opts.buffersize)\n        if numeric_buffersize is None:\n            parser.error('invalid buffer size specified')\n        opts.buffersize = numeric_buffersize\n    if opts.http_chunk_size is not None:\n        numeric_chunksize = FileDownloader.parse_bytes(opts.http_chunk_size)\n        if not numeric_chunksize:\n            parser.error('invalid http chunk size specified')\n        opts.http_chunk_size = numeric_chunksize\n    if opts.playliststart <= 0:\n        raise ValueError('Playlist start must be positive')\n    if opts.playlistend not in (-1, None) and opts.playlistend < opts.playliststart:\n        raise ValueError('Playlist end must be greater than playlist start')\n    if opts.extractaudio:\n        if opts.audioformat not in ['best', 'aac', 'flac', 'mp3', 'm4a', 'opus', 'vorbis', 'wav']:\n            parser.error('invalid audio format specified')\n    if opts.audioquality:\n        opts.audioquality = opts.audioquality.strip('k').strip('K')\n        if not opts.audioquality.isdigit():\n            parser.error('invalid audio quality specified')\n    if opts.recodevideo is not None:\n        if opts.recodevideo not in ['mp4', 'flv', 'webm', 'ogg', 'mkv', 'avi']:\n            parser.error('invalid video recode format specified')\n    if opts.convertsubtitles is not None:\n        if opts.convertsubtitles not in ['srt', 'vtt', 'ass', 'lrc']:\n            parser.error('invalid subtitle format specified')\n\n    if opts.date is not None:\n        date = DateRange.day(opts.date)","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/ytdl-org/youtube-dl/blob/956b8c585591b401a543e409accb163eeaaa1193/youtube_dl/__init__.py#L186-L222","documentation":"Raised by youtube-dl's Windows UTF-8 console writer (write_string path) when a call to the Win32 API WriteConsoleW returns 0 — i.e. the console rejected the write — after the code has already carefully chunked the string to handle non-BMP (astral) characters as surrogate pairs. 'Failed to write string' therefore means the console handle itself failed, not a Unicode-edge-case bug in chunking.","triggerScenarios":"Writing progress/status output to a Windows console (tty) where WriteConsoleW fails: the handle was invalidated (window closed, console detached, piped mid-run), a console with a broken state (legacy conhost issues, redirected handle not backed by a console), or edge cases in old Windows/Python combinations. Only reachable on Windows when sys.stderr/stdout is a real console.","commonSituations":"User closes the console window or presses Ctrl+C during a long download; running under a terminal emulator whose console handle is flaky (older mintty/conhost wrappers); scripting youtube-dl on Windows with output redirected inconsistently; Windows 7/8 legacy console limits.","solutions":["If you do not need console colors/Unicode, redirect output: youtube-dl ... > out.log 2>&1, which bypasses the WriteConsoleW path entirely (falls back to normal stream writes).","Set PYTHONIOENCODING=utf-8 or run via python -X utf8 to steer encoding behavior on newer Pythons.","Update youtube-dl / move to yt-dlp; console output handling on Windows has been hardened significantly.","If embedding, wrap the download call and treat OSError from the output layer as a stop signal (the console is gone) rather than retrying."],"exampleFix":"# before: writing directly, console may reject\nwrite_string(message + '\\n', sys.stderr)\n\n# after: guard the console-write path\ntry:\n    write_string(message + '\\n', sys.stderr)\nexcept OSError:\n    with open('youtube-dl.log', 'a', encoding='utf-8') as f:\n        f.write(message + '\\n')","handlingStrategy":"try-catch","validationCode":"import sys\n\ndef console_ok():\n    # only trust a real, healthy console handle on Windows\n    if sys.platform != 'win32':\n        return True\n    import ctypes\n    return ctypes.windll.kernel32.GetConsoleMode(\n        ctypes.windll.kernel32.GetStdHandle(-12), ctypes.byref(ctypes.c_uint32())\n    ) != 0","typeGuard":null,"tryCatchPattern":"from youtube_dl.utils import write_string\ntry:\n    write_string(msg + '\\n', sys.stderr)\nexcept OSError as e:\n    if 'Failed to write string' in str(e):\n        with open('youtube-dl.log', 'a', encoding='utf-8') as f:  # console is gone\n            f.write(msg + '\\n')\n    else:\n        raise","preventionTips":["Redirect output to a file when embedding youtube-dl on Windows to bypass WriteConsoleW entirely.","Treat an OSError from the output layer as 'console disappeared' — stop writing rather than retrying.","Keep console output ASCII-short on legacy Windows consoles, or set PYTHONIOENCODING=utf-8."],"tags":["windows","console","unicode","output"],"backgroundTag":null,"analyzedSha":"956b8c585591b401a543e409accb163eeaaa1193","analyzedAt":"2026-08-14T18:59:47.863Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}