{"record":{"id":"6db7f7c1c9a99aeb","repo":"git-ecosystem/git-credential-manager","slug":"a-non-cancelled-non-yielded-response-must-carry-a","errorCode":null,"errorMessage":"A non-cancelled, non-yielded response must carry a credential. Use Cancel() or Yield() instead.","messagePattern":"A non-cancelled, non-yielded response must carry a credential\\. Use Cancel\\(\\) or Yield\\(\\) instead\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Core/GitResponse.cs","lineNumber":68,"sourceCode":"            (isContinue && isYielded) ||\n            (isCancelled && isYielded))\n        {\n            throw new ArgumentException(\n                \"A response can be at most one of Continue, Cancel, or Yield.\");\n        }\n\n        bool hasCredential = credential is not null;\n\n        if ((isCancelled || isYielded) && hasCredential)\n        {\n            throw new ArgumentException(\n                \"A cancelled or yielded response cannot carry a credential.\",\n                nameof(credential));\n        }\n\n        if (!isCancelled && !isYielded && !hasCredential)\n        {\n            throw new ArgumentNullException(\n                nameof(credential),\n                \"A non-cancelled, non-yielded response must carry a credential. Use Cancel() or Yield() instead.\");\n        }\n\n        Credential = credential;\n        IsContinue = isContinue;\n        IsCancelled = isCancelled;\n        IsYielded = isYielded;\n    }\n\n    /// <summary>\n    /// Construct a successful response carrying the given credential.\n    /// </summary>\n    /// <remarks>Equivalent to <see cref=\"Ok(ICredential)\"/>.</remarks>\n    public GitResponse(ICredential credential)\n        : this(credential, isContinue: false, isCancelled: false, isYielded: false)\n    {\n    }","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/GitResponse.cs#L50-L86","documentation":"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.","triggerScenarios":"Calling the GitResponse(ICredential) constructor, GitResponse.Ok(credential), or GitResponse.Continue(credential) with a null credential (or a null-returning factory method).","commonSituations":"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.","solutions":["Decide the intended semantic: if the provider declines, return GitResponse.Cancel(); if it has nothing to contribute, return GitResponse.Yield().","Only construct Ok/Continue responses with a non-null ICredential; check credential != null first.","If the credential may be absent, wrap construction: credential is null ? GitResponse.Yield() : GitResponse.Ok(credential)."],"exampleFix":"// before\nreturn GitResponse.Ok(lookupResult); // lookupResult may be null\n// after\nreturn lookupResult is not null\n    ? GitResponse.Ok(lookupResult)\n    : GitResponse.Yield();","handlingStrategy":"validation","validationCode":"if (credential is null)\n    return GitResponse.Yield(); // or Cancel(), per provider semantics\nreturn GitResponse.Ok(credential);","typeGuard":"static bool HasCredential(GitResponse r) => r.Credential is not null || r.IsCancelled || r.IsYielded;","tryCatchPattern":"try { return GitResponse.Ok(credential); }\ncatch (ArgumentNullException) { return GitResponse.Yield(); }","preventionTips":["Treat null credential as a semantic decision (Cancel vs Yield), never as input to Ok().","Null-check credential-returning lookups immediately where they occur.","Prefer the static factories Ok/Cancel/Yield over the raw constructor."],"tags":["csharp","null-argument","credential","git-credential-manager"],"backgroundTag":"null-argument","analyzedSha":"e8ce762cd04b4100ae637b5fbf39ef9d0a96561e","analyzedAt":"2026-09-11T17:15:08.753Z","contentChangedAt":"2026-09-11T17:15:08.753Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}