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

Invalid 'protocol' request argument (cannot be empty)

Error message

Invalid 'protocol' request argument (cannot be empty)

What it means

EnsureMinimumRequest rejects a 'protocol' argument that is present but empty or whitespace-only (string.IsNullOrWhiteSpace). Unlike error 50 (null), here the caller supplied protocol= with no value. The library requires a concrete scheme to build the credential target/URL.

Solutions

  1. Fix the input so `protocol=` carries a real scheme (https, http, ssh).
  2. In shell wrappers, guard the variable: abort or default it if empty before composing the input.
  3. If constructing a GitRequest in code, validate the scheme string is non-empty before calling.
  4. Trace with GCM_TRACE=1 to confirm the exact input GCM received.

Example fix

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

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

Strategy: validation

Validate before calling

if (request.Protocol != null && string.IsNullOrWhiteSpace(request.Protocol))
    throw new ArgumentException("protocol must be a non-empty scheme like https");

Type guard

bool HasNonEmptyProtocol(GitRequest r) => !string.IsNullOrWhiteSpace(r.Protocol);

Try / catch

try
{
    credentialHelper.Invoke(request);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("protocol") && ex.Message.Contains("empty"))
{
    // repair the empty protocol value and retry once
}

Prevention

When it happens

Trigger: ExecuteAsync -> EnsureMinimumRequest where request.Protocol is non-null but null/whitespace, e.g. a literal `protocol=` line with an empty value in the credential input.

Common situations: Shell scripts that build the credential input with an unset variable (`protocol=$SCHEME` where SCHEME is empty); config generation that writes empty protocol keys; parsing bugs in wrapper tools that split on '=' and lose the value.

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/455e3e173e1f41ce. Report an issue: GitHub.

Appendix: source

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

            Context.Trace.WriteDictionarySecrets(inputDict, new []{ "password" }, StringComparer.OrdinalIgnoreCase);
            IHostProvider provider = await _hostProviderRegistry.GetProviderAsync(request);
            Context.Trace.WriteLine($"Host provider '{provider.Name}' was selected.");

            await ExecuteInternalAsync(request, provider);

            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>

View on GitHub (pinned to e8ce762cd0)