babalae/better-genshin-impact · warning · ArgumentOutOfRangeException

milliseconds 不能小于 0

Error message

milliseconds 不能小于 0

What it means

Thrown by DecodeDataUri when the data URI string contains no comma separator. A valid data URI has the form data:[<mediatype>][;base64],<data> — the comma separates metadata from payload. IndexOf(',') returning -1 means the string is malformed and cannot be split.

Source

Thrown at BetterGenshinImpact/Core/BgiVision/BvFlowAction.cs:170

    public BvFlow WaitUntilDisappear(BvLocator target, int? timeout = null, int? retryInterval = null)
    {
        ArgumentNullException.ThrowIfNull(target);
        ValidateWaitOptions(timeout, retryInterval);
        return CompleteOnce().WaitUntilDisappear(target, timeout, retryInterval);
    }

    public BvFlow WaitUntilAllDisappear(object targets, int? timeout = null, int? retryInterval = null)
    {
        _ = BvFlow.ParseTargets(targets, nameof(targets));
        ValidateWaitOptions(timeout, retryInterval);
        return CompleteOnce().WaitUntilAllDisappear(targets, timeout, retryInterval);
    }

    public BvFlow Wait(int milliseconds)
    {
        if (milliseconds < 0)
        {
            throw new ArgumentOutOfRangeException(nameof(milliseconds), "milliseconds 不能小于 0");
        }

        return CompleteOnce().Wait(milliseconds);
    }

    public BvFlow UntilText(string text, Rect rect = default)
    {
        return Until(_flow.CreateTextLocator(text, rect));
    }

    public BvFlow UntilAnyText(object texts, Rect rect = default)
    {
        return Until(_flow.CreateAnyTextLocator(texts, rect));
    }

    public BvFlow Until(BvLocator target)
    {
        ArgumentNullException.ThrowIfNull(target);

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Regenerate the data URI with a proper base64 payload (data:image/png;base64,<base64>).
  2. Validate data URIs before embedding in Markdown — ensure they contain a comma with non-empty data after it.
  3. If the data URI is user-provided, validate format and show a diagnostic instead of throwing.

Example fix

// before
var commaIndex = dataUri.IndexOf(',');
if (commaIndex < 0)
    throw new InvalidDataException("无效的图片 data URI。");

// after — log the malformed URI and return placeholder
var commaIndex = dataUri.IndexOf(',');
if (commaIndex < 0)
{
    _owner.ReportDiagnostic(new MarkdownDiagnostic(MarkdownDiagnosticSeverity.Warning,
        $"无效的 data URI(缺少逗号分隔符):{dataUri.Substring(0, Math.Min(50, dataUri.Length))}..."));
    return Array.Empty<byte>();
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate data URI structure before decoding
if (!rawSource.StartsWith("data:", StringComparison.OrdinalIgnoreCase)) return null;
var comma = rawSource.IndexOf(',');
if (comma < 0 || comma == rawSource.Length - 1) return null;

Type guard

static bool IsValidDataUri(string s) =>
    s.StartsWith("data:", StringComparison.OrdinalIgnoreCase) && s.IndexOf(',') > 5;

Try / catch

try { bytes = DecodeDataUri(source.OriginalString); }
catch (InvalidDataException) { return MarkdownImageResult.Placeholder; }

Prevention

When it happens

Trigger: DecodeDataUri receives a string where dataUri.IndexOf(',') < 0. Triggered by Markdown embedding a broken data URI like data:image/png with no payload, or a truncated/copy-paste-corrupted data URI.

Common situations: Script generates a data URI but omits the payload after truncation, a copy-paste cut the string at the comma, or the URI was URL-decoded prematurely stripping structure.

Related errors


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