babalae/better-genshin-impact · error · ArgumentNullException
独立任务对象不能为空
Error message
独立任务对象不能为空
What it means
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.
Source
Thrown at BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs:128
/// <summary>
/// 运行独立任务
/// </summary>
/// <param name="soloTask">
/// 支持的任务名称:
/// - AutoGeniusInvokation: 启动自动七圣召唤任务
/// - AutoWood: 启动自动伐木任务
/// - AutoFight: 启动自动战斗任务
/// - AutoDomain: 启动自动秘境任务
/// </param>
/// <param name="customCt">自定义取消令牌,允许从JS控制任务取消</param>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="ArgumentException"></exception>
public async Task<object?> RunTask(SoloTask soloTask, CancellationToken? customCt = null)
{
if (soloTask == null)
{
throw new ArgumentNullException(nameof(soloTask), "独立任务对象不能为空");
}
var taskSettingsPageViewModel = App.GetService<TaskSettingsPageViewModel>();
if (taskSettingsPageViewModel == null)
{
throw new ArgumentNullException(nameof(taskSettingsPageViewModel), "内部视图模型对象为空");
}
CancellationToken cancellationToken;
if (customCt != null)
{
cancellationToken = customCt.Value;
}
else
{
// 如果没有自定义令牌,就使用全局令牌View on GitHub (pinned to a7cb36712d)
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.
Example fix
// before (JS)
dispatcher.RunTask(task); // task is undefined
// after (JS)
if (!task) { throw new Error('SoloTask must be constructed before RunTask'); }
dispatcher.RunTask(task); Defensive patterns
Strategy: validation
Validate before calling
// JS side
if (!soloTask) throw new Error('SoloTask must be constructed before RunTask');
dispatcher.RunTask(soloTask); Type guard
// JS
function isSoloTask(v) { return v != null && typeof v === 'object' && typeof v.Name === 'string'; } Prevention
- Construct SoloTask before passing it to RunTask.
- Use a JS wrapper that null-checks task objects.
- Assign task variables at declaration.
When it happens
Trigger: 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.
Common situations: Script author forgot `new SoloTask('AutoDomain')`. Refactor left a dangling reference. A loop variable was not initialized.
Related errors
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/cd5e1c731b7149a1.
Report an issue: GitHub.