{"record":{"id":"8b40d2708b1e61af","repo":"subhra74/xdm","slug":"generic-errorcode","errorCode":"Generic","errorMessage":"ErrorCode.Generic","messagePattern":"ErrorCode\\.Generic","errorType":"error_code","errorClass":"AssembleFailedException","httpStatus":null,"severity":"error","filePath":"app/XDM/XDM.Core/Downloader/Progressive/SingleHttp/SingleSourceHTTPDownloader.cs","lineNumber":443,"sourceCode":"                                {\r\n                                    throw new AssembleFailedException(\r\n                                        res == MediaProcessingResult.AppNotFound ? ErrorCode.FFmpegNotFound :\r\n                                        ErrorCode.FFmpegError); //TODO: Add more info about error\r\n                                }\r\n\r\n                                if (Config.Instance.FetchServerTimeStamp)\r\n                                {\r\n                                    try\r\n                                    {\r\n                                        File.SetLastWriteTime(TargetFile, state.LastModified);\r\n                                    }\r\n                                    catch { }\r\n                                }\r\n                                this.totalSize = totalBytes;\r\n                            }\r\n                            else\r\n                            {\r\n                                throw new AssembleFailedException(ErrorCode.Generic); //TODO: Add more info about error\r\n                            }\r\n                        }\r\n                    }\r\n                    finally\r\n                    {\r\n#if !NET35\r\n                        System.Buffers.ArrayPool<byte>.Shared.Return(buf);\r\n#endif\r\n                    }\r\n\r\n                    if (this.cancelFlag.IsCancellationRequested) return;\r\n\r\n                    //Console.WriteLine(\"Total bytes written: {0} total size: {1}\", totalBytes, this.totalSize);\r\n                    if (this.totalSize < 1)\r\n                    {\r\n                        this.totalSize = totalBytes;\r\n                    }\r\n                    if (Config.Instance.FetchServerTimeStamp)\r","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/subhra74/xdm/blob/1ca5a25aae007826c859c81bea494e7c102e1242/app/XDM/XDM.Core/Downloader/Progressive/SingleHttp/SingleSourceHTTPDownloader.cs#L425-L461","documentation":"AssembleFailedException(ErrorCode.Generic) is thrown by SingleSourceHTTPDownloader.AssemblePieces when the downloaded file pieces cannot be merged into the final file and no more specific error code applies. In this code path the assembly loop reached a state where the expected piece data was inconsistent (e.g. a piece missing, its size not matching the expected total, or the aggregated bytes not equal to totalSize). The TODO in the source admits the code carries no detail, so 'Generic' means 'piece-set inconsistency during final merge'.","triggerScenarios":"Calling Resume() on a single-source HTTP download whose on-disk part files do not sum to a consistent set: a piece file is missing or empty, piece sizes do not reconcile with totalBytes, or the pieces list state does not match what was written to disk.","commonSituations":"Resuming a download after a crash or forced kill that left partial/corrupt .part files; moving the download's data directory without all part files; disk cleanup tools deleting part files; mixing state files from different XDM versions.","solutions":["Delete the download's part files and restart the download from scratch.","Verify all piece files exist in Config.DataDir and their sizes are non-zero and consistent with the saved state.","Check free disk space and permissions in the target directory, then retry Resume().","If reproducible, capture logs (Log.Debug output) and file a bug; the code explicitly lacks detailed error info (TODO)."],"exampleFix":"// before\nthrow new AssembleFailedException(ErrorCode.Generic);\n// after\n// Delete parts and re-download when assembly state is inconsistent:\ncatch (AssembleFailedException)\n{\n    downloader.DeleteFileParts();\n    downloader.StartDownload(); // restart instead of resume\n}","handlingStrategy":"try-catch","validationCode":"var state = DownloadStateIO.LoadSingleSourceHTTPDownloaderState(id);\nvar dir = Config.DataDir;\nlong expected = state.TotalSize;\nlong actual = state.Pieces.Sum(p => File.Exists(p.Path) ? new FileInfo(p.Path).Length : 0);\nbool resumable = expected > 0 && Math.Abs(actual - expected) < 1024 * 1024;\nif (!resumable) downloader.DeleteFileParts(); // restart instead of resume","typeGuard":"static bool HasConsistentPieces(SingleSourceHTTPDownloaderState s) =>\n    s != null && s.Pieces != null && s.Pieces.Count > 0 && s.Pieces.All(p => p != null && p.Path != null);","tryCatchPattern":"try\n{\n    downloader.Resume();\n}\ncatch (AssembleFailedException ex) when (ex.ErrorCode == ErrorCode.Generic)\n{\n    Log.Debug($\"piece set inconsistent for {downloader.Id}; restarting\");\n    downloader.DeleteFileParts();\n    downloader.StartDownload();\n}","preventionTips":["Never kill the app or shut down while a download is in the assembling phase.","Exclude the download/data directories from antivirus real-time scanning and cleanup tools.","Keep adequate free disk space so merged output writes are not interrupted.","Move or copy downloads together with ALL part files and the state file."],"tags":["download","file-assembly","resume","state-corruption"],"backgroundTag":"download-assemble-failed","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"}