babalae/better-genshin-impact · error · ArgumentException

仓库URL不能为空

Error message

仓库URL不能为空

What it means

Thrown by UpdateCenterRepoByGitCore when the repoUrl argument is null or empty. This is a pre-condition guard before performing git clone or fetch operations via LibGit2Sharp. The method operates inside a SemaphoreSlim lock (_repoWriteLock) so the check happens after acquiring the lock.

Source

Thrown at BetterGenshinImpact/Core/Script/ScriptRepoUpdater.cs:779

    public async Task<(string, bool)> UpdateCenterRepoByGit(string repoUrl, CheckoutProgressHandler? onCheckoutProgress)
    {
        await _repoWriteLock.WaitAsync();
        try
        {
            return await UpdateCenterRepoByGitCore(repoUrl, onCheckoutProgress);
        }
        finally
        {
            _repoWriteLock.Release();
        }
    }

    private async Task<(string, bool)> UpdateCenterRepoByGitCore(string repoUrl, CheckoutProgressHandler? onCheckoutProgress)
    {
        if (string.IsNullOrEmpty(repoUrl))
        {
            throw new ArgumentException("仓库URL不能为空", nameof(repoUrl));
        }

        var repoPath = Path.Combine(ReposPath, GetRepoFolderName(repoUrl));
        var updated = false;

        // 备份相关变量
        string? oldRepoJsonContent = null;

        await Task.Run(() =>
        {
            Repository? repo = null;
            try
            {
                GlobalSettings.SetOwnerValidation(false);
                if (!Directory.Exists(repoPath))
                {
                    // 如果仓库不存在,执行浅克隆操作
                    _logger.LogInformation($"浅克隆仓库: {repoUrl} 到 {repoPath}");

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Provide a valid git repository URL (HTTPS or SSH format): 'https://github.com/user/repo.git'.
  2. Validate the URL is non-empty before calling UpdateCenterRepoByGit.
  3. Check the repository configuration source (repo.json, settings) for missing URL fields.
  4. Add a UI-level validation requiring a non-empty URL before triggering repo updates.

Example fix

// before
await updater.UpdateCenterRepoByGit("", null);
// after
await updater.UpdateCenterRepoByGit("https://github.com/user/repo.git", null);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(repoUrl))
    throw new ArgumentException("Repository URL must not be empty", nameof(repoUrl));

Type guard

static bool IsValidRepoUrl(string url) =>
    !string.IsNullOrWhiteSpace(url) && Uri.TryCreate(url, UriKind.Absolute, out _);

Try / catch

try
{
    await updater.UpdateCenterRepoByGit(repoUrl, null);
}
catch (ArgumentException ex) when (ex.Message.Contains("仓库URL不能为空"))
{
    TaskControl.Logger.LogError("Repository URL is empty, skipping update");
}

Prevention

When it happens

Trigger: Calling UpdateCenterRepoByGit(repoUrl, ...) with null, empty string, or whitespace-only repoUrl. This is typically called from higher-level repo update methods that should have validated the URL beforehand.

Common situations: A script repository configuration has a missing or blank URL field. A repo.json or settings file references a repository with an empty URL. A UI input field for repository URL was left blank. Programmatic caller didn't validate before invoking.

Related errors


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