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

Missing 'host' request argument

Error message

Missing 'host' request argument

What it means

EnsureMinimumRequest requires a 'host' argument: the hostname of the remote Git server for which credentials are being stored/retrieved. request.Host was null, so GCM cannot identify which credential to look up. Thrown as a Trace2InvalidOperationException.

Solutions

  1. Include a `host=<hostname>` line (e.g. host=github.com) in the credential input.
  2. When building a GitRequest in code, set request.Host to the remote server hostname.
  3. Verify `git remote -v` URLs are well-formed so Git derives the host correctly.
  4. Re-run with GCM_TRACE=1 to inspect the parsed request fields.

Example fix

// before (programmatic request missing host)
var request = new GitRequest { Protocol = "https" };

// after
var request = new GitRequest { Protocol = "https", Host = "github.com" };
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(request.Host))
    throw new ArgumentException("host must be provided, e.g. github.com");

Type guard

bool HasHost(GitRequest r) => !string.IsNullOrEmpty(r.Host);

Try / catch

try
{
    await command.ExecuteAsync(input);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("'host'"))
{
    // log the raw input; require a host before proceeding
}

Prevention

When it happens

Trigger: ExecuteAsync -> EnsureMinimumRequest where request.Host is null — the credential input lacked a `host=` line or the request builder never populated Host.

Common situations: Manual/automated `git credential` invocations missing the host line; helpers or scripts feeding GCM only protocol/path; corrupted git configuration for a remote; integration tests that construct partial GitRequest objects.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

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

            Context.Trace.WriteLine($"End '{Name}' command...");
        }

        protected virtual void EnsureMinimumRequest(GitRequest request)
        {
            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)