{"record":{"id":"b2c9709a430489a8","repo":"babalae/better-genshin-impact","slug":"error-b2c970","errorCode":null,"errorMessage":"下载的图片内容为空。","messagePattern":"下载的图片内容为空。","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"warning","filePath":"BetterGenshinImpact/Service/BannerImageService.cs","lineNumber":129,"sourceCode":"                int read;\n                while ((read = await responseStream\n                           .ReadAsync(buffer.AsMemory(), linkedCancellationToken)\n                           .ConfigureAwait(false)) > 0)\n                {\n                    totalBytes += read;\n                    if (totalBytes > MaxDownloadBytes)\n                    {\n                        throw new InvalidDataException($\"图片大小超过 {MaxDownloadBytes / 1024 / 1024} MB 限制。\");\n                    }\n\n                    await fileStream\n                        .WriteAsync(buffer.AsMemory(0, read), linkedCancellationToken)\n                        .ConfigureAwait(false);\n                }\n\n                if (totalBytes == 0)\n                {\n                    throw new InvalidDataException(\"下载的图片内容为空。\");\n                }\n            }\n\n            ValidateImage(tempPath);\n            linkedCancellationToken.ThrowIfCancellationRequested();\n\n            lock (_fileCommitLock)\n            {\n                if (operationId != Volatile.Read(ref _latestOperationId))\n                {\n                    return false;\n                }\n\n                linkedCancellationToken.ThrowIfCancellationRequested();\n                // 保存图片到本地\n                File.Move(tempPath, NetworkImagePath, true);\n            }\n","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/BannerImageService.cs#L111-L147","documentation":"An InvalidDataException thrown by DownloadAndSaveAsync after the stream loop completes if totalBytes is zero. It rejects an empty body: the request succeeded (EnsureSuccessStatusCode passed) but no image bytes were received, so the file would be invalid/empty. This runs before ValidateImage so it gives a clearer message than an image-decode failure.","triggerScenarios":"The server returns HTTP 200 with an empty body (Content-Length 0 or a chunked stream that yields no data). The URL technically resolved and responded, but delivered zero bytes.","commonSituations":"A broken/expired image link that returns 200 with no body; a host requiring auth/cookies that silently returns empty; a CDN edge returning an empty object; a misconfigured URL pointing at a directory or non-image resource that returns nothing.","solutions":["Verify the URL points to a real, accessible image (open it in a browser).","If the host requires auth/headers, configure the HttpClient accordingly or use a direct link.","Retry once in case of a transient empty response from the CDN.","Catch InvalidDataException and prompt the user to supply a valid image URL."],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"// No reliable pre-check for an empty 200 body; verify the URL resolves to a real image.\n// Optionally HEAD the URL and reject Content-Length == 0 when the host reports it.","typeGuard":"null","tryCatchPattern":"try { var ok = await _banner.DownloadAndSaveAsync(url, ct); }\ncatch (InvalidDataException ex) { Toast.Warning(ex.Message); }","preventionTips":["Verify the URL points to a real, accessible image.","Retry once for transient empty CDN responses.","Catch InvalidDataException and prompt for a valid URL."],"tags":["download","validation","empty-response","http"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}