git-ecosystem/git-credential-manager · error · Trace2Exception
Missing 'code' in response
Error message
Missing 'code' in response
What it means
GetTwoFactorCodeViaHelperAsync asks the UI helper for a two-factor authentication code and expects a 'code' key in the response dictionary. If the helper returns without it — the 2FA dialog was abandoned or the helper malfunctioned — this Trace2Exception is thrown because no 2FA code can be returned to the caller.
Solutions
- Retry authentication and complete the 2FA dialog by entering the code
- Verify GCM/helper versions match and reinstall if the helper is outdated or corrupted
- Enable GCM_TRACE and run the helper manually to inspect its raw response for errors
- Switch to an auth mode that avoids 2FA prompts (PAT with appropriate scopes, or OAuth browser flow)
Example fix
// before
var code = await auth.GetTwoFactorCodeAsync(uri, isSms: true);
UseCode(code);
// after
try
{
var code = await auth.GetTwoFactorCodeAsync(uri, isSms: true);
UseCode(code);
}
catch (Trace2Exception ex) when (ex.Message == "Missing 'code' in response")
{
trace.WriteLine("2FA helper returned no code; aborting or retrying.");
throw new TwoFactorCancelledException(ex);
} Defensive patterns
Strategy: try-catch
Validate before calling
// Prefer PAT/OAuth flows that bypass 2FA prompts entirely // git config --global credential.github.com.gitHubAuthModes browser,pat code null;
Try / catch
try
{
string code = await auth.GetTwoFactorCodeAsync(uri, isSms);
}
catch (Trace2Exception ex) when (ex.Message == "Missing 'code' in response")
{
// 2FA dialog abandoned or helper failed; surface as cancellation and allow retry
throw new TwoFactorCancelledException(ex);
} Prevention
- Complete the 2FA dialog rather than closing it; closing cancels the flow
- Use PAT or OAuth browser authentication to avoid interactive 2FA prompts
- Keep SMS codes handy before starting the flow so the prompt isn't abandoned
- Update GCM/helper as a unit to prevent response-key contract drift
When it happens
Trigger: Invoking GetTwoFactorCodeAsync (e.g. during basic-auth 2FA challenge) and the helper's result dictionary lacks 'code': user closed the 2FA prompt, helper crashed, or an incompatible helper version omitted the key.
Common situations: Users skipping the 2FA code entry dialog; helper process failures on machines with broken UI dependencies; SMS 2FA flow interrupted before the code arrives and is entered; legacy helper versions with different output keys.
Related errors
- Missing 'mode' in response
- Missing 'pat' in response
- Missing 'username' in response
- Missing 'password' in response
- Unknown mode value in response
AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11).
Data as JSON: /api/errors/3301171dbe932888.
Report an issue: GitHub.
Appendix: source
Thrown at src/GitHub/GitHubAuthentication.cs:403
Context.Console.WriteLine(isSms
? "An SMS containing the authentication code has been sent to your registered device."
: "Use your registered authentication app to generate an authentication code.");
return await TerminalPrompts.CreateText("Authentication code").ShowAsync(Context.Console);
}
private async Task<string> GetTwoFactorCodeViaHelperAsync(bool isSms, string args, string command)
{
var promptArgs = new StringBuilder(args);
promptArgs.Append("2fa");
if (isSms) promptArgs.Append(" --sms");
IDictionary<string, string> resultDict = await InvokeHelperAsync(command, promptArgs.ToString(), null);
if (!resultDict.TryGetValue("code", out string authCode))
{
throw new Trace2Exception(Context.Trace2, "Missing 'code' in response");
}
return authCode;
}
public async Task<OAuth2TokenResult> GetOAuthTokenViaBrowserAsync(Uri targetUri, IEnumerable<string> scopes, string loginHint)
{
ThrowIfUserInteractionDisabled();
var oauthClient = new GitHubOAuth2Client(HttpClient, Context.Settings, targetUri, Context.Trace2);
// Can we launch the user's default web browser?
if (!Context.SessionManager.IsWebBrowserAvailable)
{
throw new Trace2InvalidOperationException(Context.Trace2,
"Browser authentication requires a desktop session");
}
View on GitHub (pinned to e8ce762cd0)