{"record":{"id":"05d4ae11080c70c4","repo":"EllanJiang/GameFramework","slug":"task-is-invalid","errorCode":null,"errorMessage":"Task is invalid.","messagePattern":"Task is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Download/DownloadManager.DownloadAgent.cs","lineNumber":180,"sourceCode":"            {\n                Dispose();\n\n                m_Helper.DownloadAgentHelperUpdateBytes -= OnDownloadAgentHelperUpdateBytes;\n                m_Helper.DownloadAgentHelperUpdateLength -= OnDownloadAgentHelperUpdateLength;\n                m_Helper.DownloadAgentHelperComplete -= OnDownloadAgentHelperComplete;\n                m_Helper.DownloadAgentHelperError -= OnDownloadAgentHelperError;\n            }\n\n            /// <summary>\n            /// 开始处理下载任务。\n            /// </summary>\n            /// <param name=\"task\">要处理的下载任务。</param>\n            /// <returns>开始处理任务的状态。</returns>\n            public StartTaskStatus Start(DownloadTask task)\n            {\n                if (task == null)\n                {\n                    throw new GameFrameworkException(\"Task is invalid.\");\n                }\n\n                m_Task = task;\n\n                m_Task.Status = DownloadTaskStatus.Doing;\n                string downloadFile = Utility.Text.Format(\"{0}.download\", m_Task.DownloadPath);\n\n                try\n                {\n                    if (File.Exists(downloadFile))\n                    {\n                        m_FileStream = File.OpenWrite(downloadFile);\n                        m_FileStream.Seek(0L, SeekOrigin.End);\n                        m_StartLength = m_SavedLength = m_FileStream.Length;\n                        m_DownloadedLength = 0L;\n                    }\n                    else\n                    {","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Download/DownloadManager.DownloadAgent.cs#L162-L198","documentation":"DownloadAgent.Start requires a non-null DownloadTask because the agent needs the task's download URL, path, and tag to do any work. This error means Start was called with a null task, so the agent has nothing to process.","triggerScenarios":"Calling DownloadAgent.Start(task) with task == null, usually from a custom DownloadManager task loop or when the task queue returned null.","commonSituations":"Custom scheduling code that pops from an empty/nullable task collection, passing a task struct boxed incorrectly, or initializing agents before tasks are queued.","solutions":["Only call Start with a task obtained from DownloadManager's task queue","Check the task dequeuing logic for null when no task is available","Ensure the task was created through DownloadManager.AddTask so it is properly formed"],"exampleFix":"// before\nDownloadTask task = GetNextTask(); // may be null\nagent.Start(task);\n// after\nDownloadTask task = GetNextTask();\nif (task != null) agent.Start(task);","handlingStrategy":"type-guard","validationCode":"if (task == null) return StartTaskStatus.UnknownError; // or skip iteration","typeGuard":"bool HasTask(DownloadTask task) => task != null;","tryCatchPattern":"try { agent.Start(task); } catch (GameFrameworkException ex) { Log.Error(\"Download agent start failed: {0}\", ex.Message); }","preventionTips":["Dequeue tasks only through DownloadManager's own queue logic","Handle empty-queue cases explicitly instead of passing null","Never cache task references that may be nulled on shutdown"],"tags":["download","null-argument","task","unity","gameframework"],"backgroundTag":"null-argument","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}