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

A non-cancelled, non-yielded response must carry a…

Error message

A non-cancelled, non-yielded response must carry a credential. Use Cancel() or Yield() instead.

What it means

GitResponse has exactly four legal shapes: Ok/Continue (must carry a credential), Cancel and Yield (must NOT carry one). The private constructor enforces this invariant: if the response is neither cancelled nor yielded and no ICredential was supplied, it throws ArgumentNullException. The message tells you the correct API: use GitResponse.Cancel() or GitResponse.Yield() to express 'no credential' instead of passing null.

Solutions

  1. Decide the intended semantic: if the provider declines, return GitResponse.Cancel(); if it has nothing to contribute, return GitResponse.Yield().
  2. Only construct Ok/Continue responses with a non-null ICredential; check credential != null first.
  3. If the credential may be absent, wrap construction: credential is null ? GitResponse.Yield() : GitResponse.Ok(credential).

Example fix

// before
return GitResponse.Ok(lookupResult); // lookupResult may be null
// after
return lookupResult is not null
    ? GitResponse.Ok(lookupResult)
    : GitResponse.Yield();
Defensive patterns

Strategy: validation

Validate before calling

if (credential is null)
    return GitResponse.Yield(); // or Cancel(), per provider semantics
return GitResponse.Ok(credential);

Type guard

static bool HasCredential(GitResponse r) => r.Credential is not null || r.IsCancelled || r.IsYielded;

Try / catch

try { return GitResponse.Ok(credential); }
catch (ArgumentNullException) { return GitResponse.Yield(); }

Prevention

When it happens

Trigger: Calling the GitResponse(ICredential) constructor, GitResponse.Ok(credential), or GitResponse.Continue(credential) with a null credential (or a null-returning factory method).

Common situations: A host provider whose credential lookup returns null (no stored credential, failed OAuth flow) and the developer passes the result straight to Ok()/new GitResponse() instead of choosing Cancel or Yield; refactors where a credential field became nullable.

Related errors


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

Appendix: source

Thrown at src/Core/GitResponse.cs:68

            (isContinue && isYielded) ||
            (isCancelled && isYielded))
        {
            throw new ArgumentException(
                "A response can be at most one of Continue, Cancel, or Yield.");
        }

        bool hasCredential = credential is not null;

        if ((isCancelled || isYielded) && hasCredential)
        {
            throw new ArgumentException(
                "A cancelled or yielded response cannot carry a credential.",
                nameof(credential));
        }

        if (!isCancelled && !isYielded && !hasCredential)
        {
            throw new ArgumentNullException(
                nameof(credential),
                "A non-cancelled, non-yielded response must carry a credential. Use Cancel() or Yield() instead.");
        }

        Credential = credential;
        IsContinue = isContinue;
        IsCancelled = isCancelled;
        IsYielded = isYielded;
    }

    /// <summary>
    /// Construct a successful response carrying the given credential.
    /// </summary>
    /// <remarks>Equivalent to <see cref="Ok(ICredential)"/>.</remarks>
    public GitResponse(ICredential credential)
        : this(credential, isContinue: false, isCancelled: false, isYielded: false)
    {
    }

View on GitHub (pinned to e8ce762cd0)