babalae/better-genshin-impact · error · NotSupportedException

JS脚本入参错误:错误的foodEffectType

Error message

JS脚本入参错误:错误的foodEffectType

What it means

NotSupportedException thrown at line 262 in the default branch of the foodEffectType switch. The int value does not match any defined FoodEffectType case (ATKBoostingDish, AdventurersDish, DEFBoostingDish). ScriptObjectConverter.GetValue retrieved a value, so the key existed — it just was not a valid enum member.

Source

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

                                        break;
                                    case FoodEffectType.AdventurersDish:
                                        foodName = pathingPartyConfig.AutoEatConfig.DefaultAdventurersDishName;
                                        if (foodName == null)
                                        {
                                            _logger.LogInformation("缺少{Text}配置,跳过吃Buff", "默认的冒险类料理");
                                            return null;
                                        }
                                        break;
                                    case FoodEffectType.DEFBoostingDish:
                                        foodName = pathingPartyConfig.AutoEatConfig.DefaultDefBoostingDishName;
                                        if (foodName == null)
                                        {
                                            _logger.LogInformation("缺少{Text}配置,跳过吃Buff", "默认的防御类料理");
                                            return null;
                                        }
                                        break;
                                    default:
                                        throw new NotSupportedException("JS脚本入参错误:错误的foodEffectType");
                                }
                            }
                        }
                    }

                    var autoEatConfig = TaskContext.Instance().Config.AutoEatConfig;
                    return await new AutoEatTask(new AutoEatParam()
                    {
                        CheckInterval = autoEatConfig.CheckInterval,
                        EatInterval = autoEatConfig.EatInterval,
                        ShowNotification = autoEatConfig.ShowNotification,
                        FoodName = foodName
                    }).Start(cancellationToken);
                }
            case "CountInventoryItem":
                {
                    if (soloTask.Config == null)
                    {

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Use a valid FoodEffectType value: ATKBoostingDish, AdventurersDish, or DEFBoostingDish (check the enum for current underlying ints).
  2. Prefer referencing the enum by name if the JS bridge exposes it rather than hardcoding ints.
  3. If you authored the enum, ensure every member has a case in this switch.

Example fix

// before (JS)
new SoloTask('AutoEat', { foodEffectType: 9 }) // no such case -> throws

// after (JS) — use a valid FoodEffectType value
new SoloTask('AutoEat', { foodEffectType: 1 }) // e.g. ATKBoostingDish
Defensive patterns

Strategy: validation

Validate before calling

// JS side
const VALID_EFFECTS = new Set([/* ATKBoostingDish, AdventurersDish, DEFBoostingDish ints */]);
if (foodEffectType != null && !VALID_EFFECTS.has(foodEffectType)) {
  throw new Error(`Invalid foodEffectType: ${foodEffectType}`);
}

Prevention

When it happens

Trigger: JS sets `foodEffectType` to an int outside the enum's range (e.g. 0, 4, 99) or to a value whose underlying int does not correspond to a handled case. Note: the switch handles three named cases; any other int (including a valid-but-unhandled future enum value) hits default.

Common situations: Author guessed the numeric value. Enum was extended with new members not yet cased here. Off-by-one or zero-based vs one-based confusion.

Related errors


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