babalae/better-genshin-impact · error · ArgumentNullException

背包物品计数参数不能为空

Error message

背包物品计数参数不能为空

What it means

ArgumentNullException thrown by RunCountInventoryItemTask at line 449 when the CountInventoryItemParam argument is null. Unlike the RunTask('CountInventoryItem') path (errors 69-70), this typed overload takes a ready CountInventoryItemParam directly; a null param has no grid/item data.

Source

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

        {
            throw new ArgumentNullException(nameof(param), "自动幽境危战任务参数不能为空");
        }

        CancellationToken cancellationToken = customCt ?? CancellationContext.Instance.Cts.Token;
        await new AutoStygianOnslaughtTask(param).Start(cancellationToken);
    }
    
    /// <summary>
    /// 运行背包物品计数任务。
    /// </summary>
    /// <param name="param">背包物品计数参数。</param>
    /// <param name="customCt">自定义取消令牌。</param>
    /// <returns>单物品返回数量;多物品返回名称到数量的脚本对象。</returns>
    public async Task<object?> RunCountInventoryItemTask(CountInventoryItemParam param, CancellationToken? customCt = null)
    {
        if (param == null)
        {
            throw new ArgumentNullException(nameof(param), "背包物品计数参数不能为空");
        }

        CancellationToken cancellationToken = customCt ?? CancellationContext.Instance.Cts.Token;
        object result = await new CountInventoryItem(param).Start(cancellationToken);

        if (param.ItemName != null)
        {
            return result;
        }
        else
        {
            dynamic expando = new ExpandoObject();
            var expandoDict = (IDictionary<string, object>)expando;
            foreach (var kvp in (Dictionary<string, int>)result)
            {
                expandoDict[kvp.Key] = kvp.Value;
            }

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Construct CountInventoryItemParam with GridScreenName and ItemName/ItemNames before calling.
  2. Null-check in JS before invoking.

Example fix

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

// after (JS)
const cParam = new CountInventoryItemParam({ GridScreenName: '5x10', ItemName: 'Mora' });
dispatcher.RunCountInventoryItemTask(cParam);
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

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

Prevention

When it happens

Trigger: JS calls `dispatcher.RunCountInventoryItemTask(null)` or passes an undefined variable.

Common situations: Author forgot to construct CountInventoryItemParam. Param built conditionally and the branch did not run.

Related errors


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