babalae/better-genshin-impact · warning · Exception

角色死亡后重试次数不能小于 0

Error message

角色死亡后重试次数不能小于 0

What it means

Validate 校验 ReviveRetryCount(角色死亡后重试次数)不能为负,< 0 即抛 Exception。这是数值合法性校验,防止负重试导致循环逻辑异常。

Source

Thrown at BetterGenshinImpact/GameTask/AutoBoss/AutoBossTask.cs:1000

    /// 校验自动首领讨伐启动所需的 Boss、战斗策略、讨伐次数、补充树脂开关、重试次数和路线文件。
    /// </summary>
    /// <exception cref="Exception">配置缺失、Boss 不支持、策略不存在或重试次数非法时抛出。</exception>
    /// <exception cref="FileNotFoundException">必需路线文件不存在时抛出。</exception>
    private void Validate()
    {
        if (string.IsNullOrWhiteSpace(_taskParam.BossName))
        {
            throw new Exception("请选择需要讨伐的首领");
        }

        if (!AutoBossData.IsSupportedBoss(_taskParam.BossName))
        {
            throw new Exception($"暂不支持首领:{_taskParam.BossName}");
        }

        if (_taskParam.ReviveRetryCount < 0)
        {
            throw new Exception("角色死亡后重试次数不能小于 0");
        }

        if (_taskParam.SpecifyRunCount && _taskParam.RunCount < 1)
        {
            throw new Exception("指定讨伐次数必须大于 0");
        }

        if (!_taskParam.SpecifyRunCount && (_taskParam.UseTransientResin || _taskParam.UseFragileResin))
        {
            throw new Exception("只有指定讨伐次数模式才能开启须臾树脂或脆弱树脂补充");
        }

        if (string.IsNullOrWhiteSpace(_taskParam.CombatStrategyPath))
        {
            _taskParam.SetCombatStrategyPath(_taskParam.StrategyName);
        }

        if (!File.Exists(_taskParam.CombatStrategyPath) && !Directory.Exists(_taskParam.CombatStrategyPath))

View on GitHub (pinned to a7cb36712d)

Solutions

  1. 将 ReviveRetryCount 设为 0 或正整数(0 表示不重试)。
  2. 在 UI 用数值控件限定最小值 0。
  3. 反序列化后 clamp 到非负。

Example fix

// before
if (_taskParam.ReviveRetryCount < 0)
{
    throw new Exception("角色死亡后重试次数不能小于 0");
}

// after
_taskParam.ReviveRetryCount = Math.Max(0, _taskParam.ReviveRetryCount);
Defensive patterns

Strategy: validation

Validate before calling

_taskParam.ReviveRetryCount = Math.Max(0, _taskParam.ReviveRetryCount);
// UI 数值控件 Minimum=0

Prevention

When it happens

Trigger: 用户在界面/配置文件将 ReviveRetryCount 设为负数;配置序列化或迁移产生负值。

Common situations: 手动编辑配置;UI 数值控件允许负输入;旧配置字段含义变更。

Related errors


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