babalae/better-genshin-impact · warning · InvalidOperationException

添加流程步骤后不能修改流程默认配置

Error message

添加流程步骤后不能修改流程默认配置

What it means

Thrown when the image URI's scheme is not one of the supported schemes: data, file, pack, http, or https. The final else branch in LoadAsync catches all other schemes (e.g. ftp, blob, custom) with a NotSupportedException naming the unrecognized scheme.

Source

Thrown at BetterGenshinImpact/Core/BgiVision/BvFlow.cs:474

        lock (_syncRoot)
        {
            if (_hasStarted)
            {
                throw new InvalidOperationException("BvFlow 已经开始执行,不能再添加步骤");
            }

            _hasSteps = true;
            _steps.Add(new BvFlowStep(description, action));
        }

        return this;
    }

    private void EnsureDefaultsCanChange()
    {
        if (_hasSteps)
        {
            throw new InvalidOperationException("添加流程步骤后不能修改流程默认配置");
        }
    }

    private sealed record BvFlowStep(string Description, Func<BvFlowExecutionContext, Task> Action);

}

internal sealed record BvFlowConditionResult(bool Succeeded, Region? Match);

internal sealed class BvFlowExecutionContext
{
    public Rect? LastMatchRect { get; set; }

    public (double X, double Y) GetLastMatchCenter()
    {
        if (LastMatchRect is not { } rect)
        {
            throw new InvalidOperationException("没有可用的上一步识别位置,无法执行隐式坐标操作");

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Convert the image reference to a supported scheme (http, https, data, or local file path).
  2. If a custom scheme is needed, subclass MarkdownImageLoader and add a branch for it.
  3. Pre-validate image URIs in the Markdown parser before passing to LoadAsync.

Example fix

// before
else
{
    throw new NotSupportedException($"不支持的图片协议:{source.Scheme}");
}

// after — degrade gracefully with diagnostic
else
{
    _owner.ReportDiagnostic(new MarkdownDiagnostic(MarkdownDiagnosticSeverity.Warning,
        $"不支持的图片协议:{source.Scheme},已跳过。"));
    return MarkdownImageResult.Placeholder;
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate scheme before loading
var scheme = source.Scheme.ToLowerInvariant();
if (scheme is not ("data" or "file" or "pack" or "http" or "https"))
    return MarkdownImageResult.Placeholder;

Type guard

static bool IsSupportedScheme(Uri source) =>
    source.Scheme.ToLowerInvariant() is "data" or "file" or "pack" or "http" or "https";

Try / catch

try { /* load */ }
catch (NotSupportedException) { return MarkdownImageResult.Placeholder; }

Prevention

When it happens

Trigger: LoadAsync receives a Uri whose Scheme is not data/file/pack/http/https. Triggered by Markdown referencing an image with an unsupported protocol like ftp://, ws://, or a custom-virtual scheme injected by a script.

Common situations: Script-generated Markdown uses a custom URI scheme, a typo produces a malformed scheme, or a content source uses a protocol this loader doesn't support (e.g. ftp).

Related errors


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