{"record":{"id":"6cd0ca6a09fb54b9","repo":"nilaoda/N_m3u8DL-RE","slug":"resstring-loadurlfailed","errorCode":null,"errorMessage":"ResString.loadUrlFailed","messagePattern":"ResString\\.loadUrlFailed","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/N_m3u8DL-RE.Parser/StreamExtractor.cs","lineNumber":52,"sourceCode":"            this.rawText = await File.ReadAllTextAsync(uri.LocalPath);\n            parserConfig.OriginalUrl = parserConfig.Url = url;\n        }\n        else if (url.StartsWith(\"http\"))\n        {\n            parserConfig.OriginalUrl = url;\n            (this.rawText, url) = await HTTPUtil.GetWebSourceAndNewUrlAsync(url, parserConfig.Headers);\n            parserConfig.Url = url;\n        }\n        else if (File.Exists(url))\n        {\n            url = Path.GetFullPath(url);\n            this.rawText = await File.ReadAllTextAsync(url);\n            parserConfig.OriginalUrl = parserConfig.Url = new Uri(url).AbsoluteUri;\n        }\n\n        if (string.IsNullOrWhiteSpace(rawText))\n        {\n            throw new Exception(ResString.loadUrlFailed);\n        }\n        \n        this.rawText = rawText.Trim();\n        LoadSourceFromText(this.rawText);\n    }\n\n    [MemberNotNull(nameof(rawText), nameof(extractor))]\n    private void LoadSourceFromText(string rawText)\n    {\n        var rawType = \"txt\";\n        rawText = rawText.Trim();\n        this.rawText = rawText;\n        if (rawText.StartsWith(HLSTags.ext_m3u))\n        {\n            Logger.InfoMarkUp(ResString.matchHLS);\n            extractor = new HLSExtractor(parserConfig);\n            rawType = \"m3u8\";\n        }","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/nilaoda/N_m3u8DL-RE/blob/e113dee70c924ee08dae5460624909b04d84cb76/src/N_m3u8DL-RE.Parser/StreamExtractor.cs#L34-L70","documentation":"StreamExtractor.LoadSourceFromUrlAsync fetches the playlist/stream source from a URL (or reads a local file) and then parses the text. If the resulting rawText is null or whitespace — meaning the fetch produced no content — it throws ResString.loadUrlFailed. This guards downstream parsers (M3U8, etc.) from empty input.","triggerScenarios":"LoadSourceFromUrlAsync is called with a URL whose response body is empty/whitespace, a local file that is empty, or the underlying download returned nothing.","commonSituations":"Server returns 200 with empty body; network middleware strips the body; the local file path points to an empty file; proxy or firewall intercepts the request; URL points to a page that requires cookies/headers.","solutions":["Verify the URL returns non-empty content (curl the URL and inspect the body).","Check required headers/cookies (User-Agent, Referer, auth) that the server may demand before serving content.","If loading a local file, confirm the file exists and is non-empty.","Inspect proxy/VPN/firewall interference; retry the request.","Catch the exception and surface the raw response (status code, body length) to diagnose the upstream server."],"exampleFix":"// before\nvar text = await DownloadTextAsync(url);\n// after\nvar text = await DownloadTextAsync(url);\nif (string.IsNullOrWhiteSpace(text))\n    throw new Exception($\"loadUrlFailed: empty response (status={status}, len={text?.Length ?? 0}) from {url}\");","handlingStrategy":"try-catch","validationCode":"// probe the URL before handing it to StreamExtractor\nusing var resp = await httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);\nif (!resp.IsSuccessStatusCode) throw new HttpRequestException($\"HTTP {(int)resp.StatusCode} for {url}\");\nvar probe = await resp.Content.ReadAsStringAsync();\nif (string.IsNullOrWhiteSpace(probe)) throw new InvalidDataException($\"empty response from {url}\");","typeGuard":null,"tryCatchPattern":"try { await extractor.LoadSourceFromUrlAsync(url); }\ncatch (Exception ex) when (ex.Message == ResString.loadUrlFailed) {\n    logger.Error($\"Failed to load source from {url}: empty or blank response\");\n    // retry with different headers or fail over to a mirror URL\n}","preventionTips":["Probe URLs with curl before automating downloads.","Send required User-Agent/Referer/Cookie headers.","Check response status and body length before parsing.","Verify local files are non-empty before passing file:// paths."],"tags":["network","http","empty-response"],"backgroundTag":"empty-response-body","analyzedSha":"e113dee70c924ee08dae5460624909b04d84cb76","analyzedAt":"2026-09-13T02:43:21.078Z","contentChangedAt":"2026-09-13T02:43:21.078Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}