babalae/better-genshin-impact · warning · ArgumentException

URL不能为空

Error message

URL不能为空

What it means

Thrown by HtmlMask.Show when the url parameter is null, empty, or consists only of whitespace. The Show method is the entry point for displaying an HTML overlay window; it requires either an http(s) URL or a file path relative to the script's working directory.

Source

Thrown at BetterGenshinImpact/Core/Script/Dependence/HtmlMask.cs:80

    private readonly object _openedWindowsLock = new();
    private bool _disposed;

    public HtmlMask(string workDir)
    {
        _workDir = workDir;
    }

    #region 窗口管理

    /// <summary>
    /// 显示HTML遮罩窗口
    /// </summary>
    public string Show(string url, string? id = null)
    {
        try
        {
            if (string.IsNullOrWhiteSpace(url))
                throw new ArgumentException("URL不能为空");

            string finalUrl;

            if (url.StartsWith("http", StringComparison.OrdinalIgnoreCase))
            {
                finalUrl = url;
            }
            else
            {
                // 禁止 file:// 绝对路径,仅允许脚本目录下的相对路径
                string absPath = ScriptUtils.NormalizePath(_workDir, url);
                finalUrl = new Uri(absPath).AbsoluteUri;
            }

            string windowId = HtmlMaskWindow.Show(finalUrl, id, _workDir);

            _toHtmlQueues[windowId] = new ConcurrentQueue<Message>();
            _fromHtmlQueues[windowId] = new ConcurrentQueue<Message>();

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Check string.IsNullOrWhiteSpace(url) before calling Show and provide a default or error message.
  2. Validate the config source: ensure the URL/path key exists and is non-empty.
  3. Log the resolved URL at debug level to catch empty values early.

Example fix

// before
htmlMask.Show(config["overlayUrl"]);

// after
var url = config["overlayUrl"];
if (string.IsNullOrWhiteSpace(url))
    throw new ArgumentException("overlayUrl must be specified in config");
htmlMask.Show(url);
Defensive patterns

Strategy: validation

Validate before calling

// Validate URL before calling Show
if (string.IsNullOrWhiteSpace(url))
    throw new ArgumentException("URL cannot be null or empty", nameof(url));
htmlMask.Show(url, windowId);

Prevention

When it happens

Trigger: Calling htmlMask.Show(url) where url is null, "", or " ". This can happen when a script reads a URL from config and the config key is missing or empty.

Common situations: Script reads an HTML file path from a JSON manifest but the key is absent, producing null. Dynamic URL construction results in an empty string due to a missing template variable. Pass-through from an unvalidated user input field.

Related errors


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