{"record":{"id":"90c09e2a2a97f288","repo":"babalae/better-genshin-impact","slug":"stage","errorCode":null,"errorMessage":"未知的定义字段：{stage}","messagePattern":"未知的定义字段：(.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/GameTask/AutoGeniusInvokation/ScriptParser.cs","lineNumber":110,"sourceCode":"                        {\n                            int delta = int.Parse(RegexHelper.ExcludeNumberRegex().Replace(actionParts[3], \"\"));\n                            actionCommand.DiceDelta = delta;\n                        }\n                        else if (actionParts[3].StartsWith(\"骰子减少\"))\n                        {\n                            int delta = int.Parse(RegexHelper.ExcludeNumberRegex().Replace(actionParts[3], \"\"));\n                            actionCommand.DiceDelta = -delta;\n                        }\n                        else\n                        {\n                            MyAssert(false, $\"策略中的行动命令解析错误：骰子增减参数格式不正确（应为 骰子增加N 或 骰子减少N ），实际：{actionParts[3]}\");\n                        }\n                    }\n                    duel.ActionCommandQueue.Add(actionCommand);\n                }\n                else\n                {\n                    throw new System.Exception($\"未知的定义字段：{stage}\");\n                }\n            }\n\n            MyAssert(duel.Characters[3] != null, \"角色未定义，请确认策略文本格式是否为UTF-8\");\n        }\n        catch (System.Exception ex)\n        {\n            MyLogger.LogError($\"解析脚本错误，行号：{i + 1}，错误信息：{ex}\");\n            ThemedMessageBox.Error($\"解析脚本错误，行号：{i + 1}，错误信息：{ex}\", \"策略解析失败\");\n            return default!;\n        }\n\n        return duel;\n    }\n\n    /// <summary>\n    /// 解析示例\n    /// 角色1=刻晴|雷{技能3消耗=1雷骰子+2任意,技能2消耗=3雷骰子,技能1消耗=4雷骰子}","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/AutoGeniusInvokation/ScriptParser.cs#L92-L128","documentation":"Thrown by ScriptParser.Parse when a script line is encountered under a stage header (a line ending with ':') that is neither '角色定义:' nor '策略定义:'. The parser uses a simple state machine: lines containing ':' set the current stage, and all subsequent non-empty, non-comment lines are dispatched based on that stage string. An unrecognized stage means the script contains a typo in a header, an unsupported section, or a stray colon in a data line that was misinterpreted as a header.","triggerScenarios":"A user-authored TCG strategy script contains a header like '角色定义 :' (extra space), '角色definition:' (wrong language), '战斗策略:' (unsupported section), or a data line that contains a ':' making the parser treat it as a new stage. After the stage is set, the next data line hits the else branch and throws.","commonSituations":"Strategy script copied from a wiki with formatting artifacts, manual edits introducing typos in section headers, BOM or encoding issues causing the header string to not match exactly, or a script written for a newer/older parser version with different supported sections.","solutions":["Open the strategy script and verify every header line is exactly '角色定义:' or '策略定义:' with no extra spaces or characters.","Check that no data lines (character or action definitions) contain a ':' character, which would be misinterpreted as a stage header.","Ensure the file is saved as UTF-8 without BOM."],"exampleFix":"// before — script with bad header\n角色定义 :\n角色1=刻晴|雷{...}\n\n// after\n角色定义:\n角色1=刻晴|雷{...}","handlingStrategy":"validation","validationCode":"// Before parsing, validate that all stage headers are recognized\nvar validStages = new HashSet<string> { \"角色定义:\", \"策略定义:\" };\nforeach (var line in scriptLines)\n{\n    var trimmed = line.Trim();\n    if (trimmed.Contains(':') && !trimmed.StartsWith(\"//\"))\n    {\n        var stageHeader = trimmed.Contains(':') ? trimmed : null;\n        // If a line looks like a header but is not recognized, warn early\n    }\n}","typeGuard":"public static bool IsValidStageHeader(string line)\n{\n    return line == \"角色定义:\" || line == \"策略定义:\";\n}","tryCatchPattern":"catch (System.Exception ex) when (ex.Message.Contains(\"未知的定义字段\"))\n{\n    MyLogger.LogError($\"脚本包含未知的段落标题，请检查格式。错误: {ex.Message}\");\n    ThemedMessageBox.Error($\"策略脚本格式错误：{ex.Message}\", \"解析失败\");\n    return default!;\n}","preventionTips":["Only use '角色定义:' and '策略定义:' as section headers in TCG strategy scripts.","Avoid using ':' in character/action definition lines to prevent misinterpretation as a header.","Save strategy scripts as UTF-8 without BOM."],"tags":["tcg","script-parsing","configuration","user-input"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}