babalae/better-genshin-impact · error · Exception

未找到等级对应的行:\n{levelAndMinorAffixLines}

Error message

未找到等级对应的行:\n{levelAndMinorAffixLines}

What it means

Thrown in the level-parsing region when no line in levelAndMinorAffixLines matches '^\+(\d*)$'. The artifact's enhancement level (shown as '+N') could not be located. SingleOrDefault returns null when zero lines match.

Source

Thrown at BetterGenshinImpact/GameTask/AutoArtifactSalvage/AutoArtifactSalvageTask.cs:732

            }
            minorAffixes.Add(new ArtifactAffix(artifactAffixType, affixValue, isUnactivated));
        }
        #endregion

        #region 等级
        string levelLine = levelAndMinorAffixLines.Select(l =>
        {
            string pattern = @"^\+(\d*)$";
            Match match = Regex.Match(l, pattern);
            if (match.Success)
            {
                return match.Groups[1].Value;
            }
            else
            {
                return null;
            }
        }).Where(l => l != null).Cast<string>().SingleOrDefault() ?? throw new Exception($"未找到等级对应的行:\n{levelAndMinorAffixLines}");
        if (!int.TryParse(levelLine, out int level) || level < 0 || level > 20)
        {
            throw new Exception($"未识别的等级:{levelLine}");
        }
        #endregion

        return new ArtifactStat(name, mainAffix, minorAffixes.ToArray(), level);
    }

    public static ArtifactStatus GetArtifactStatus(Mat src)
    {
        using Mat upperLine = new Mat(src, new Rect(0, 0, src.Width, (int)(src.Height * 0.19)));
        //using Mat hsvMat = upperLine.CvtColor(ColorConversionCodes.BGR2HSV_FULL);
        //var pixel_hsv_pink = hsvMat.At<Vec3b>(17, 12);    // 注意是(Y,X)
        //var pixel_hsv_grren = hsvMat.At<Vec3b>(8, 105);   // 注意是(Y,X)

        // 粉色锁
        Scalar pinkhsv = OpenCvCommonHelper.CommonHSV2OpenCVHSVFull(new Scalar(9, 0.54, 1.00));

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Inspect levelAndMinorAffixLines to see what was captured.
  2. Handle the level-0 case (no '+') by defaulting to 0 instead of throwing.
  3. Update the regex if the level format changed.
  4. Verify the ROI crop percentages match the current card layout.

Example fix

// before
string levelLine = ...SingleOrDefault() ?? throw new Exception($"未找到等级对应的行:\n{levelAndMinorAffixLines}");
// after - tolerate level 0 (no +N shown)
string? levelLine = ...SingleOrDefault();
int level = 0;
if (levelLine != null && (!int.TryParse(levelLine, out level) || level < 0 || level > 20))
    throw new Exception($"未识别的等级:{levelLine}");
Defensive patterns

Strategy: validation

Validate before calling

static string? FindLevelLine(IEnumerable<string> lines) =>
    lines.Select(l => Regex.Match(l, @"^\+(\d*)$")).Where(m => m.Success).Select(m => m.Groups[1].Value).SingleOrDefault();

Prevention

When it happens

Trigger: OCR did not capture the '+N' level text; the level line uses a different format (e.g. 'Lv. N' after a UI change); the level region crop shifted; the artifact is level 0 and shows no '+' (then no line matches).

Common situations: UI scale/layout change moving the level out of levelAndMinorAffixRoi; game version changing the level display format; OCR weakness on the small '+' glyph; a level-0 artifact with no visible plus.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/d9d3e8204d948d03. Report an issue: GitHub.