babalae/better-genshin-impact · warning · FormatException
无法解析音符 {keys} 的时值:{value}
Error message
无法解析音符 {keys} 的时值:{value} What it means
Thrown by MusicScoreParser.ParseYuanQinTokens(string) when the content inside the duration brackets [...] cannot be parsed as a number. The value before an optional '-' separator is parsed with double.TryParse using invariant culture; if it fails, the entire bracket value is reported as unparseable.
Source
Thrown at BetterGenshinImpact/GameTask/Music/Service/MusicScoreParser.cs:329
{
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}");
}
tokens.Add(new YuanQinToken(keys, denominator, special));
}
return tokens;
}
private static List<YuanQinToken> ParseYuanQinTokens(JArray notes)
{
var tokens = new List<YuanQinToken>(notes.Count);
foreach (var item in notes)
{
if (item is not JObject note)
{
throw new FormatException("yuanqin 音符数组中包含非对象元素");
}
View on GitHub (pinned to a7cb36712d)
Solutions
- Inspect the duration bracket content reported in the error message and ensure the part before any '-' is a valid number.
- Review yuanqin syntax: duration is a number, optionally followed by '-' and a special modifier (e.g. '#', '*', '$', 'none').
- Fix the score file to use valid numeric durations.
Defensive patterns
Strategy: validation
Validate before calling
// Validate duration values are numeric
foreach (Match m in Regex.Matches(sheet, @"\[([^\]]+)\]"))
{
var val = m.Groups[1].Value.Split('-')[0];
if (!double.TryParse(val, CultureInfo.InvariantCulture, out _))
logger.LogError("无法解析时值:{Value}", m.Groups[1].Value);
} Try / catch
var score = await parser.ParseAsync(path, rootFolder, ct);
if (!string.IsNullOrEmpty(score.Error)) { logger.LogWarning(score.Error); } Prevention
- Ensure duration brackets contain valid numeric values before any '-' separator.
- Follow yuanqin syntax: [number] or [number-special].
- Validate the sheet with a syntax checker.
When it happens
Trigger: A yuanqin sheet where the duration bracket contains non-numeric text before the separator. Valid values are like '1', '2', '1-#', '8-*'. Invalid: 'x', 'abc', or any non-numeric leading segment.
Common situations: Manual score authoring with a typo in the duration value; an unsupported special character placed before the '-' separator; a score format from an incompatible tool.
Related errors
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/4063972d2a8ada36.
Report an issue: GitHub.