babalae/better-genshin-impact · error · ArgumentNullException

战斗任务参数不能为空

Error message

战斗任务参数不能为空

What it means

ArgumentNullException thrown by RunAutoFightTask at line 370 when the AutoFightParam argument is null. AutoFightParam carries CombatStrategyPath which is immediately used (line 374) to resolve a combat task factory — a null param would NPE one line later anyway, so the guard fails fast with a clear message.

Source

Thrown at BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs:370

        {
            throw new ArgumentNullException(nameof(param), "自动首领讨伐任务参数不能为空");
        }

        CancellationToken cancellationToken = customCt ?? CancellationContext.Instance.Cts.Token;
        return await new AutoBossTask(param).Start(cancellationToken);
    }

    /// <summary>  
    /// 运行自动战斗任务
    /// </summary>  
    /// <param name="param">战斗任务参数</param>  
    /// <param name="customCt">自定义取消令牌</param>  
    /// <returns></returns>  
    public async Task RunAutoFightTask(AutoFightParam param, CancellationToken? customCt = null)  
    {  
        if (param == null)  
        {  
            throw new ArgumentNullException(nameof(param), "战斗任务参数不能为空");  
        }  
  
        CancellationToken cancellationToken = customCt ?? CancellationContext.Instance.Cts.Token;  
        var factory = GameTask.AutoFight.Factory.CombatTaskFactoryProvider.GetFactory(param.CombatStrategyPath);
        var fightTask = factory.CreateTask(param);
        await fightTask.Start(cancellationToken);  
    }
    
    /// <summary>
    /// 运行简易战斗策略脚本。
    /// 使用策略语言直接控制角色执行动作(如 e、q、attack 等),适合快速操作。
    /// </summary>
    /// <param name="script">策略字符串,支持逗号/换行/分号分隔指令,可选角色名前缀</param>
    /// <param name="avatarName">指定操作的角色名(可选,不指定则操作当前角色)</param>
    /// <param name="customCt">自定义取消令牌</param>
    public async Task RunCombatScript(string script, string? avatarName = null, CancellationToken? customCt = null)
    {
        if (string.IsNullOrWhiteSpace(script))

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Construct AutoFightParam with a valid CombatStrategyPath before calling.
  2. Null-check in JS before invoking.
  3. Ensure the strategy file exists so construction does not silently yield null.

Example fix

// before (JS)
dispatcher.RunAutoFightTask(param); // null -> throws

// after (JS)
const fightParam = new AutoFightParam(combatStrategyPath);
dispatcher.RunAutoFightTask(fightParam);
Defensive patterns

Strategy: validation

Validate before calling

// JS side
if (!param) throw new Error('AutoFightParam is required');
dispatcher.RunAutoFightTask(param);

Type guard

// JS
function isAutoFightParam(v) { return v != null && typeof v === 'object' && typeof v.CombatStrategyPath !== 'undefined'; }

Prevention

When it happens

Trigger: JS calls `dispatcher.RunAutoFightTask(null)`. A param built conditionally was never assigned.

Common situations: Author forgot to construct AutoFightParam. Combat strategy path not resolved before construction.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/cc6b742dbf91d3ad. Report an issue: GitHub.