{"record":{"id":"9b923e5e516e2c98","repo":"babalae/better-genshin-impact","slug":"json-9b923e","errorCode":null,"errorMessage":"JSON 战斗策略中未定义任何动作","messagePattern":"JSON 战斗策略中未定义任何动作","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/GameTask/AutoFight/Script/JsonCombatStrategyParser.cs","lineNumber":69,"sourceCode":"            throw new InvalidOperationException($\"JSON 战斗策略格式错误：{ex.Message}\", ex);\n        }\n\n        if (strategy == null)\n        {\n            Logger.LogError(\"JSON 战斗策略反序列化结果为空\");\n            throw new InvalidOperationException(\"JSON 战斗策略反序列化失败\");\n        }\n\n        if (strategy.Info == null)\n        {\n            Logger.LogError(\"JSON 战斗策略缺少 Info 节点\");\n            throw new InvalidOperationException(\"JSON 战斗策略缺少 Info 节点\");\n        }\n\n        if (strategy.Actions == null || strategy.Actions.Count == 0)\n        {\n            Logger.LogError(\"JSON 战斗策略缺少 Actions 节点或动作为空\");\n            throw new InvalidOperationException(\"JSON 战斗策略中未定义任何动作\");\n        }\n\n        // 校验动作合法性（名称需能作为条件标识符解析；index 允许重复）\n        ValidateActions(strategy.Actions);\n\n        Logger.LogInformation(\"JSON 战斗策略加载完成：{Name}，共 {Count} 个动作\",\n            strategy.Info.Name, strategy.Actions.Count);\n\n        return strategy;\n    }\n\n    /// <summary>\n    /// 校验动作名称合法性。\n    /// 动作名必须能作为条件表达式中的单个标识符解析（复用 <see cref=\"ConditionEvaluator.IsValidActionName\"/>：\n    /// 不能是布尔字面量 true/false、纯数字，不能含空白、逗号、运算符等，也不能与内置条件函数同名）。\n    /// 允许不同动作使用相同 index（since/count 等按 index 查询时取最近一次执行的事件记录）。\n    /// </summary>\n    private static void ValidateActions(List<JsonAction> actions)","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/AutoFight/Script/JsonCombatStrategyParser.cs#L51-L87","documentation":"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.","triggerScenarios":"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\": [] }`.","commonSituations":"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.","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."],"exampleFix":"// before (empty actions)\n{\n  \"Info\": { \"Name\": \"S\" },\n  \"Actions\": []\n}\n\n// after\n{\n  \"Info\": { \"Name\": \"S\" },\n  \"Actions\": [\n    { \"Name\": \"opening\", \"Index\": 1 }\n  ]\n}","handlingStrategy":"validation","validationCode":"// Pre-check for non-empty Actions array\nusing System.Text.Json;\n\nvar doc = System.Text.Json.JsonDocument.Parse(json);\nif (!doc.RootElement.TryGetProperty(\"Actions\", out var actions) || actions.ValueKind != JsonValueKind.Array || actions.GetArrayLength() == 0)\n{\n    throw new ArgumentException(\"策略必须包含至少一个动作\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var strategy = JsonCombatStrategyParser.Parse(json);\n}\ncatch (InvalidOperationException e) when (e.Message.Contains(\"未定义任何动作\"))\n{\n    Logger.LogError(\"策略未定义任何动作，请添加至少一个 Action\");\n}","preventionTips":["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."],"tags":["json-strategy","validation","empty-collection","actions"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}