git-ecosystem/git-credential-manager · error · Trace2InvalidOperationException

Invalid 'host' request argument (cannot be empty)

Error message

Invalid 'host' request argument (cannot be empty)

What it means

EnsureMinimumRequest rejects a 'host' argument that is present but empty or whitespace-only (string.IsNullOrWhiteSpace). The caller supplied `host=` with no value, which cannot identify a credential target.

Solutions

  1. Provide a real hostname on the `host=` line of the credential input.
  2. In wrappers, fail fast on an empty host variable before composing input.
  3. Validate GitRequest.Host with string.IsNullOrWhiteSpace before invoking the command in code.
  4. Check the remote URL (`git remote -v`) is complete and includes a hostname.

Example fix

// before (shell wrapper)
printf 'protocol=https\nhost=%s\n' "$HOST" | git-credential-manager store

// after
: "${HOST:?HOST must not be empty}"
printf 'protocol=https\nhost=%s\n' "$HOST" | git-credential-manager store
Defensive patterns

Strategy: validation

Validate before calling

if (request.Host != null && string.IsNullOrWhiteSpace(request.Host))
    throw new ArgumentException("host must be a non-empty hostname");

Type guard

bool HasNonEmptyHost(GitRequest r) => !string.IsNullOrWhiteSpace(r.Host);

Try / catch

try
{
    credentialHelper.Invoke(request);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("host") && ex.Message.Contains("empty"))
{
    // fix the empty host value, then retry
}

Prevention

When it happens

Trigger: ExecuteAsync -> EnsureMinimumRequest where request.Host is non-null but whitespace, e.g. an input line `host=` with an empty value.

Common situations: Scripts interpolating an empty HOST variable; tools that extract the host from a malformed remote URL and produce an empty string; templated CI configs where a host placeholder was never filled.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11). Data as JSON: /api/errors/3dcf26125b314451. Report an issue: GitHub.

Appendix: source

Thrown at src/Core/Commands/GitCommandBase.cs:76

            if (request.Protocol is null)
            {
                throw new Trace2InvalidOperationException(Context.Trace2, "Missing 'protocol' request argument");
            }

            if (string.IsNullOrWhiteSpace(request.Protocol))
            {
                throw new Trace2InvalidOperationException(Context.Trace2,
                    "Invalid 'protocol' request argument (cannot be empty)");
            }

            if (request.Host is null)
            {
                throw new Trace2InvalidOperationException(Context.Trace2, "Missing 'host' request argument");
            }

            if (string.IsNullOrWhiteSpace(request.Host))
            {
                throw new Trace2InvalidOperationException(Context.Trace2,
                    "Invalid 'host' request argument (cannot be empty)");
            }
        }

        /// <summary>
        /// Execute the command using the given <see cref="GitRequest"/> and <see cref="IHostProvider"/>.
        /// </summary>
        /// <param name="request">Input arguments of the current Git credential query.</param>
        /// <param name="provider">Host provider for the current <see cref="GitRequest"/>.</param>
        /// <returns>Awaitable task for the command execution.</returns>
        protected abstract Task ExecuteInternalAsync(GitRequest request, IHostProvider provider);
    }
}

View on GitHub (pinned to e8ce762cd0)