babalae/better-genshin-impact · error · InvalidOperationException
JSON 战斗策略中未定义任何动作
Error message
JSON 战斗策略中未定义任何动作
What it means
Thrown by JsonCombatStrategyParser.Parse when strategy.Actions is null or has zero elements. A strategy with no actions is meaningless — the parser requires at least one action to be defined. This guards against empty or incomplete strategy files.
Source
Thrown at BetterGenshinImpact/GameTask/AutoFight/Script/JsonCombatStrategyParser.cs:69
throw new InvalidOperationException($"JSON 战斗策略格式错误:{ex.Message}", ex);
}
if (strategy == null)
{
Logger.LogError("JSON 战斗策略反序列化结果为空");
throw new InvalidOperationException("JSON 战斗策略反序列化失败");
}
if (strategy.Info == null)
{
Logger.LogError("JSON 战斗策略缺少 Info 节点");
throw new InvalidOperationException("JSON 战斗策略缺少 Info 节点");
}
if (strategy.Actions == null || strategy.Actions.Count == 0)
{
Logger.LogError("JSON 战斗策略缺少 Actions 节点或动作为空");
throw new InvalidOperationException("JSON 战斗策略中未定义任何动作");
}
// 校验动作合法性(名称需能作为条件标识符解析;index 允许重复)
ValidateActions(strategy.Actions);
Logger.LogInformation("JSON 战斗策略加载完成:{Name},共 {Count} 个动作",
strategy.Info.Name, strategy.Actions.Count);
return strategy;
}
/// <summary>
/// 校验动作名称合法性。
/// 动作名必须能作为条件表达式中的单个标识符解析(复用 <see cref="ConditionEvaluator.IsValidActionName"/>:
/// 不能是布尔字面量 true/false、纯数字,不能含空白、逗号、运算符等,也不能与内置条件函数同名)。
/// 允许不同动作使用相同 index(since/count 等按 index 查询时取最近一次执行的事件记录)。
/// </summary>
private static void ValidateActions(List<JsonAction> actions)View on GitHub (pinned to a7cb36712d)
Solutions
- Add at least one action object to the 'Actions' array.
- Each action typically needs at least 'Name' and 'Index' properties.
- Refer to existing strategy files for the correct action object structure.
Example fix
// before (empty actions)
{
"Info": { "Name": "S" },
"Actions": []
}
// after
{
"Info": { "Name": "S" },
"Actions": [
{ "Name": "opening", "Index": 1 }
]
} Defensive patterns
Strategy: validation
Validate before calling
// Pre-check for non-empty Actions array
using System.Text.Json;
var doc = System.Text.Json.JsonDocument.Parse(json);
if (!doc.RootElement.TryGetProperty("Actions", out var actions) || actions.ValueKind != JsonValueKind.Array || actions.GetArrayLength() == 0)
{
throw new ArgumentException("策略必须包含至少一个动作");
} Try / catch
try
{
var strategy = JsonCombatStrategyParser.Parse(json);
}
catch (InvalidOperationException e) when (e.Message.Contains("未定义任何动作"))
{
Logger.LogError("策略未定义任何动作,请添加至少一个 Action");
} Prevention
- Ensure the Actions array contains at least one action object.
- Each action typically needs 'Name' and 'Index' at minimum.
- Use existing strategy files as templates to understand the required structure.
When it happens
Trigger: The JSON file has an 'Info' node but 'Actions' is missing, null, or an empty array. For example: `{ "Info": {...} }` with no Actions key, or `{ "Info": {...}, "Actions": [] }`.
Common situations: User starts writing a strategy file, adds the Info header, but hasn't filled in actions yet. Or the Actions array was accidentally emptied during editing.
Related errors
- JSON 战斗策略反序列化失败
- JSON 战斗策略缺少 Info 节点
- JSON 战斗策略中动作名称无法作为条件标识符解析:{action.Name}
- milliseconds 不能小于 0
- {paramName} 不能为空
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/9b923e5e516e2c98.
Report an issue: GitHub.