{"record":{"id":"021564e2fdd1b337","repo":"babalae/better-genshin-impact","slug":"error-021564","errorCode":null,"errorMessage":"候选文本不能包含空字符串或纯空白字符串","messagePattern":"候选文本不能包含空字符串或纯空白字符串","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/BgiVision/BvPage.cs","lineNumber":122,"sourceCode":"    /// </summary>\n    /// <param name=\"ro\"></param>\n    /// <returns></returns>\n    public BvLocator Locator(RecognitionObject ro)\n    {\n        return new BvLocator(ro, _cancellationToken);\n    }\n\n    public BvLocator GetByText(string text = \"\", Rect rect = default)\n    {\n        return Locator(text, rect);\n    }\n\n    public BvLocator GetByAnyText(object texts, Rect rect = default)\n    {\n        var matchTexts = ParseCollection<string>(texts, nameof(texts));\n        if (matchTexts.Any(string.IsNullOrWhiteSpace))\n        {\n            throw new ArgumentException(\"候选文本不能包含空字符串或纯空白字符串\", nameof(texts));\n        }\n\n        matchTexts = matchTexts.Distinct(StringComparer.Ordinal).ToList();\n        return new BvLocator(new RecognitionObject\n        {\n            RecognitionType = RecognitionTypes.Ocr,\n            RegionOfInterest = rect\n        }, _cancellationToken, matchTexts);\n    }\n\n    public BvLocator GetByImage(BvImage image)\n    {\n        return Locator(image);\n    }\n\n\n    public List<Region> Ocr(Rect rect = default)\n    {","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/BgiVision/BvPage.cs#L104-L140","documentation":"BvPage.GetByAnyText builds an OCR locator that matches any one of several candidate texts; it throws ArgumentException if any candidate is null, empty, or whitespace. The match set is later consumed by the OCR recognition pipeline where an empty string would either match nothing or spuriously match blank regions, so the guard validates the whole collection up front after ParseCollection has coerced it from a JS array.","triggerScenarios":"Calling GetByAnyText(new[]{ \"确认\", \"\", \"确定\" }) ; passing a JS array like [\"OK\", null, \"YES\"]; a candidate string that is only spaces.","commonSituations":"Lists assembled dynamically where one entry was never set; localized text tables with missing keys rendered as empty; trimming user input that leaves blank entries.","solutions":["Filter the candidate list before passing it: texts.Where(s => !string.IsNullOrWhiteSpace(s)).","Validate upstream that every key in your text table resolves to a non-blank value.","When building from config, skip null/blank entries at load time."],"exampleFix":"// before\nvar loc = page.GetByAnyText(new[] { \"确认\", \"\", \"确定\" });\n\n// after\nvar candidates = new[] { \"确认\", \"\", \"确定\" }\n    .Where(s => !string.IsNullOrWhiteSpace(s))\n    .ToArray();\nvar loc = page.GetByAnyText(candidates);","handlingStrategy":"validation","validationCode":"var clean = candidates\n    .Where(s => !string.IsNullOrWhiteSpace(s))\n    .Distinct(StringComparer.Ordinal)\n    .ToList();\nif (clean.Count > 0)\n    var loc = page.GetByAnyText(clean);","typeGuard":"static bool AllNonBlank(IEnumerable<string> xs) => xs.All(s => !string.IsNullOrWhiteSpace(s));","tryCatchPattern":null,"preventionTips":["Sanitize text tables at load time: drop null/blank/whitespace entries.","When building candidate lists dynamically, filter before passing to GetByAnyText.","Log dropped candidates so missing localization keys are visible."],"tags":["bgivision","ocr","locator","argument-validation"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}