babalae/better-genshin-impact · warning · FormatException
音符 {keys} 的时值缺少右方括号
Error message
音符 {keys} 的时值缺少右方括号 What it means
Thrown by MusicScoreParser.ParseYuanQinTokens(string) when a duration bracket '[' is opened but no matching ']' is found. The method uses sheet.IndexOf(']', index + 1) and throws if the result is -1.
Source
Thrown at BetterGenshinImpact/GameTask/Music/Service/MusicScoreParser.cs:312
keys = sheet[(index + 1)..end];
index = end + 1;
}
else
{
keys = sheet[index].ToString();
index++;
}
if (index >= sheet.Length || sheet[index] != '[')
{
throw new FormatException($"音符 {keys} 缺少时值");
}
var bracketEnd = sheet.IndexOf(']', index + 1);
if (bracketEnd < 0)
{
throw new FormatException($"音符 {keys} 的时值缺少右方括号");
}
var value = sheet[(index + 1)..bracketEnd];
index = bracketEnd + 1;
if (value is "^" or "&")
{
tokens.Add(new YuanQinToken(keys, 0, value));
continue;
}
var separator = value.IndexOf('-');
var denominatorText = separator >= 0 ? value[..separator] : value;
var special = separator >= 0 ? value[(separator + 1)..] : "none";
if (!double.TryParse(denominatorText, NumberStyles.Float, CultureInfo.InvariantCulture,
out var denominator))
{
throw new FormatException($"无法解析音符 {keys} 的时值:{value}");
}View on GitHub (pinned to a7cb36712d)
Solutions
- Find the unclosed '[' and add the matching ']' in the sheet string.
- Run a bracket-balance validator on the sheet before parsing.
- Check the PerformanceScore.Error property for context.
Defensive patterns
Strategy: validation
Validate before calling
// Check bracket balance
int openSq = sheet.Count(c => c == '[');
int closeSq = sheet.Count(c => c == ']');
if (openSq != closeSq) { logger.LogError("方括号不匹配"); } Try / catch
var score = await parser.ParseAsync(path, rootFolder, ct);
if (!string.IsNullOrEmpty(score.Error)) { logger.LogWarning(score.Error); } Prevention
- Balance-check square brackets in the sheet.
- Ensure every '[' has a matching ']'.
- Validate sheet syntax before playback.
When it happens
Trigger: A yuanqin sheet string where a '[' is not followed by ']'. For example, 'Q[1 W[2]' where the first bracket is never closed.
Common situations: Manual editing error; truncated sheet; copy-paste mistake that dropped the closing bracket.
Related errors
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/eddc6ca6366cc0bf.
Report an issue: GitHub.