{"record":{"id":"1c714eb95a1ce8d6","repo":"babalae/better-genshin-impact","slug":"error-1c714e","errorCode":null,"errorMessage":"角色养成识别：当前角色尚未初始化。","messagePattern":"角色养成识别：当前角色尚未初始化。","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/GameTask/CharacterDevelopment/CharacterDevelopmentTask.cs","lineNumber":258,"sourceCode":"    private AvatarGridIconRecognizer? _recognizer;\n    private int _characterIndex;\n    private CharacterSelectionTarget? _currentTarget;\n    private CharacterDevelopmentResult? _currentResult;\n    private Queue<CharacterDevelopmentCategory> _pendingCategories = new();\n    private CharacterDevelopmentCategory _currentCategory;\n    private string? _pendingElementType;\n    private string? _pendingWeaponType;\n    private List<Point> _talentPoints = [];\n    private int _talentIndex;\n    private readonly HashSet<string> _readTalentTypes = new(StringComparer.Ordinal);\n\n    protected override ILogger Logger => _logger;\n\n    private AvatarGridIconRecognizer Recognizer =>\n        _recognizer ?? throw new InvalidOperationException(\"角色养成识别：头像识别器尚未初始化。\");\n\n    private CharacterSelectionTarget CurrentTarget =>\n        _currentTarget ?? throw new InvalidOperationException(\"角色养成识别：当前角色尚未初始化。\");\n\n    private CharacterDevelopmentResult CurrentResult =>\n        _currentResult ?? throw new InvalidOperationException(\"角色养成识别：当前结果尚未初始化。\");\n\n    public CharacterDevelopmentStateMachineTask(IReadOnlyList<string> characterNames, CharacterDevelopmentCategory categories)\n    {\n        if (characterNames.Count == 0)\n        {\n            throw new ArgumentException(\"至少需要指定一个角色。\", nameof(characterNames));\n        }\n\n        if (categories == CharacterDevelopmentCategory.None)\n        {\n            throw new ArgumentException(\"至少需要指定一个读取分类。\", nameof(categories));\n        }\n\n        _categories = categories;\n        _targets = characterNames.Select(CharacterSelectionHelper.CreateTarget).ToList();","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/CharacterDevelopment/CharacterDevelopmentTask.cs#L240-L276","documentation":"Thrown by the `CurrentTarget` property getter when `_currentTarget` is null. `_currentTarget` is populated by `PrepareCharacter(index)` (line 344), which `Start()` calls once at the beginning (line 312) and the state machine calls again when advancing to each subsequent character. It is null before the first `PrepareCharacter` runs and is conceptically reset between characters.","triggerScenarios":"Accessing `CurrentTarget` before `Start()` has called `PrepareCharacter(0)`, or invoking a handler/detector that reads `CurrentTarget` outside an active run.","commonSituations":"Direct handler invocation in tests; a state-handler running before the initial `PrepareCharacter` due to a custom state-machine wiring; reading the property after the run completes.","solutions":["Enter the task exclusively via `Start()`, which calls `PrepareCharacter(0)` before running the state machine.","Ensure any custom state transitions always go through `PrepareNextCharacter` → `PrepareCharacter` so `_currentTarget` is set before handlers read it.","Avoid reading `CurrentTarget` from code outside the state-machine execution scope."],"exampleFix":"// before\nvar t = new CharacterDevelopmentStateMachineTask(names, cats);\nvar name = t.CurrentTarget.Name; // throws\n\n// after\nawait t.Start(ct); // CurrentTarget is valid only inside Start","handlingStrategy":"validation","validationCode":"// CurrentTarget is set by PrepareCharacter, called inside Start().\n// Caller code should not read it; rely on the returned results list instead.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always enter via Start(), which runs PrepareCharacter(0) first.","Read character info from the List<CharacterDevelopmentResult> returned by Start(), not CurrentTarget.","Keep PrepareNextCharacter→PrepareCharacter wired so _currentTarget is set before any handler reads it."],"tags":["state-machine","null-guard","lifecycle","character-development"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}