{"record":{"id":"cd5e1c731b7149a1","repo":"babalae/better-genshin-impact","slug":"error-cd5e1c","errorCode":null,"errorMessage":"独立任务对象不能为空","messagePattern":"独立任务对象不能为空","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs","lineNumber":128,"sourceCode":"\n    /// <summary>\n    /// 运行独立任务\n    /// </summary>\n    /// <param name=\"soloTask\">\n    /// 支持的任务名称:\n    /// - AutoGeniusInvokation: 启动自动七圣召唤任务\n    /// - AutoWood: 启动自动伐木任务\n    /// - AutoFight: 启动自动战斗任务\n    /// - AutoDomain: 启动自动秘境任务\n    /// </param>\n    /// <param name=\"customCt\">自定义取消令牌，允许从JS控制任务取消</param>\n    /// <exception cref=\"ArgumentNullException\"></exception>\n    /// <exception cref=\"ArgumentException\"></exception>\n    public async Task<object?> RunTask(SoloTask soloTask, CancellationToken? customCt = null)\n    {\n        if (soloTask == null)\n        {\n            throw new ArgumentNullException(nameof(soloTask), \"独立任务对象不能为空\");\n        }\n\n        var taskSettingsPageViewModel = App.GetService<TaskSettingsPageViewModel>();\n        if (taskSettingsPageViewModel == null)\n        {\n            throw new ArgumentNullException(nameof(taskSettingsPageViewModel), \"内部视图模型对象为空\");\n        }\n\n\n        CancellationToken cancellationToken;\n\n        if (customCt != null)\n        {\n            cancellationToken = customCt.Value;\n        }\n        else\n        {\n            // 如果没有自定义令牌，就使用全局令牌","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs#L110-L146","documentation":"ArgumentNullException thrown by Dispatcher.RunTask(SoloTask) at line 128 when the soloTask argument is null. SoloTask is the JS-facing model object (Name + optional Config) that selects which automation task to run; a null pointer here means the script never constructed one.","triggerScenarios":"JS calls `dispatcher.RunTask(null)`. A function meant to return a SoloTask returned undefined. A variable was conditionally assigned and the false branch left it null.","commonSituations":"Script author forgot `new SoloTask('AutoDomain')`. Refactor left a dangling reference. A loop variable was not initialized.","solutions":["Construct the SoloTask before calling RunTask: `dispatcher.RunTask(new SoloTask('AutoDomain'));`","Add a JS-side null check.","If the task is optional, guard the whole call instead of passing null."],"exampleFix":"// before (JS)\ndispatcher.RunTask(task); // task is undefined\n\n// after (JS)\nif (!task) { throw new Error('SoloTask must be constructed before RunTask'); }\ndispatcher.RunTask(task);","handlingStrategy":"validation","validationCode":"// JS side\nif (!soloTask) throw new Error('SoloTask must be constructed before RunTask');\ndispatcher.RunTask(soloTask);","typeGuard":"// JS\nfunction isSoloTask(v) { return v != null && typeof v === 'object' && typeof v.Name === 'string'; }","tryCatchPattern":null,"preventionTips":["Construct SoloTask before passing it to RunTask.","Use a JS wrapper that null-checks task objects.","Assign task variables at declaration."],"tags":["script","argument-null","dispatcher","solo-task","clearscript"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}