babalae/better-genshin-impact · error · ArgumentException

添加实时任务失败: {realtimeTimer.Name}

Error message

添加实时任务失败: {realtimeTimer.Name}

What it means

ArgumentException thrown by Dispatcher.AddTrigger at line 97 when TaskTriggerDispatcher.Instance().AddTrigger(name, config) returns false. AddTrigger returns false when the supplied trigger name is not a registered/known trigger type — the dispatcher cannot map the name to a concrete trigger implementation. This is the only guard that fires AFTER the timer object itself is valid, so the failure is purely about an unrecognized name.

Source

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

    /// <param name="timer"></param>
    /// <exception cref="ArgumentNullException"></exception>
    /// <exception cref="ArgumentException"></exception>
    public void AddTrigger(RealtimeTimer timer)
    {
        var realtimeTimer = timer;
        if (realtimeTimer == null)
        {
            throw new ArgumentNullException(nameof(realtimeTimer), "实时任务对象不能为空");
        }

        if (string.IsNullOrEmpty(realtimeTimer.Name))
        {
            throw new ArgumentNullException(nameof(realtimeTimer.Name), "实时任务名称不能为空");
        }

        if (!TaskTriggerDispatcher.Instance().AddTrigger(realtimeTimer.Name, realtimeTimer.Config))
        {
            throw new ArgumentException($"添加实时任务失败: {realtimeTimer.Name}", nameof(realtimeTimer.Name));
        }
    }

    public async Task RunTask(SoloTask soloTask, CancellationTokenSource customCts)
    {
        // 创建链接的取消令牌源,任何一个取消都会触发
        CancellationTokenSource linkedCts = CancellationTokenSource.CreateLinkedTokenSource(
            customCts.Token,
            CancellationContext.Instance.Cts.Token);
        await RunTask(soloTask, linkedCts.Token);
    }


    /// <summary>
    /// 运行独立任务
    /// </summary>
    /// <param name="soloTask">
    /// 支持的任务名称:

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Use a known trigger name — currently 'AutoPick' and 'AutoSkip' (see RealtimeTimer constructor branches).
  2. Verify exact spelling and casing against TaskTriggerDispatcher's registered triggers.
  3. Catch ArgumentException in JS/TS wrapper to give the script author a readable error including the rejected name.

Example fix

// before (JS)
dispatcher.AddTrigger(new RealtimeTimer('Autopick')); // typo, returns false -> throws

// after (JS)
dispatcher.AddTrigger(new RealtimeTimer('AutoPick')); // exact registered name
Defensive patterns

Strategy: validation

Validate before calling

// JS side — keep a whitelist of known trigger names
const KNOWN_TRIGGERS = ['AutoPick', 'AutoSkip'];
if (!KNOWN_TRIGGERS.includes(timer.Name)) {
  throw new Error(`Unknown trigger name: ${timer.Name}. Known: ${KNOWN_TRIGGERS.join(', ')}`);
}
dispatcher.AddTrigger(timer);

Try / catch

try { dispatcher.AddTrigger(timer); }
catch (e) { /* ArgumentException: unknown name — log and continue or fall back */ }

Prevention

When it happens

Trigger: AddTrigger(new RealtimeTimer('UnknownTrigger')) where 'UnknownTrigger' is not a registered trigger. A typo in a valid name like 'Autopick' instead of 'AutoPick'. A trigger name that exists only in a newer/older build.

Common situations: Typo or wrong casing in the trigger name (the lookup is name/case-sensitive). Feature module that registers the trigger was not loaded. Version skew between the script and the host.

Related errors


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