babalae/better-genshin-impact · warning · InvalidOperationException

一次性动作不支持 WithTimeout 或 WithRetryInterval,请使用 Until 系列方法设置重试条

Error message

一次性动作不支持 WithTimeout 或 WithRetryInterval,请使用 Until 系列方法设置重试条件

What it means

Thrown by DecodeDataUri after decoding a base64 or URL-encoded data URI payload, when the resulting byte array exceeds MaxDownloadBytes (20 MB). This is the data-URI equivalent of the file/HTTP size guards, preventing large embedded images from consuming memory.

Source

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

    public BvFlow UntilAllDisappear(object targets)
    {
        return Complete(BvFlow.ParseTargets(targets, nameof(targets)), BvFlowCondition.AllDisappear);
    }

    public Task<BvPage> Run()
    {
        return CompleteOnce().Run();
    }

    private BvFlow CompleteOnce()
    {
        lock (_syncRoot)
        {
            EnsureNotCompleted();
            if (_timeout is not null || _retryInterval is not null)
            {
                throw new InvalidOperationException(
                    "一次性动作不支持 WithTimeout 或 WithRetryInterval,请使用 Until 系列方法设置重试条件");
            }

            _completed = true;
        }

        return _flow.AddOnceActionStep(_description, _action);
    }

    private BvFlow Complete(IReadOnlyList<BvLocator> targets, BvFlowCondition condition)
    {
        int timeout;
        int retryInterval;
        lock (_syncRoot)
        {
            EnsureNotCompleted();
            _completed = true;
            timeout = _timeout ?? _flow.DefaultTimeout;

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Replace the data URI with a file reference or URL to a compressed image.
  2. Compress/resize the image before base64-encoding.
  3. Increase MaxDownloadBytes if large embedded images are expected (recompile).

Example fix

// before
if (bytes.Length > MaxDownloadBytes)
    throw new InvalidDataException($"图片大小超过 {MaxDownloadBytes / 1024 / 1024} MB 限制。");

// after — return empty and warn
if (bytes.Length > MaxDownloadBytes)
{
    _owner.ReportDiagnostic(new MarkdownDiagnostic(MarkdownDiagnosticSeverity.Warning,
        $"data URI 图片大小 {bytes.Length / 1024 / 1024} MB 超过限制,已跳过。"));
    return Array.Empty<byte>();
}
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check decoded length is infeasible without decoding;
// validate base64 length as a proxy: decoded ≈ base64len * 3/4
var estBytes = (data.Length * 3) / 4;
if (estBytes > MaxDownloadBytes) return Placeholder;

Try / catch

try { bytes = DecodeDataUri(source.OriginalString); }
catch (InvalidDataException ex) when (ex.Message.Contains("MB 限制"))
{ return MarkdownImageResult.Placeholder; }

Prevention

When it happens

Trigger: DecodeDataUri decodes the payload (base64 or UTF8 URL-decoded) and checks bytes.Length > MaxDownloadBytes. Triggered by Markdown embedding a very large base64-encoded image directly in the document.

Common situations: User pastes a full-resolution photo as a data URI into Markdown, a tool auto-embeds images as base64 without size filtering, or the Markdown document itself becomes very large from embedded data.

Understand the failure class

Related errors


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