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

Missing 'mode' in response

Error message

Missing 'mode' in response

What it means

GetAuthenticationModeViaHelperAsync invokes the platform GCM helper process and expects a 'mode' key in the returned dictionary. A Trace2Exception is thrown when the helper's response lacks that key, indicating a malformed or unexpected helper response.

Solutions

  1. Ensure the GCM helper binary version matches the library version
  2. Check the helper's stdout/stderr for error output that displaced the expected 'mode' response
  3. Re-install or update Git Credential Manager
  4. Enable Trace2 logging to capture the raw helper invocation and response
Defensive patterns

Strategy: try-catch

Validate before calling

if (resultDict == null || resultDict.Count == 0) throw new InvalidOperationException("GCM helper returned an empty response; check helper version/output.");

Type guard

bool HasMode(IDictionary<string,string> r) => r != null && r.ContainsKey("mode");

Try / catch

try { mode = await oauth.GetAuthenticationModeAsync(...); } catch (Exception ex) when (ex.Message.Contains("Missing 'mode' in response")) { /* reinstall/update helper or fall back to default mode */ }

Prevention

When it happens

Trigger: The result dictionary returned by InvokeHelperAsync contains no 'mode' entry — e.g. helper output was not parsed into the expected key/value pairs, an old/mismatched helper version responded, or the helper returned an error payload instead of a mode selection.

Common situations: Version mismatch between the GCM library and an installed git-credential-helper; corrupted or non-standard stdout from the helper; running the helper on an unexpected platform where it emits different output.

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/4f7d7f1bc80d00e0. Report an issue: GitHub.

Appendix: source

Thrown at src/Core/Authentication/OAuthAuthentication.cs:160

            {
                promptArgs.AppendFormat(" --resource {0}", QuoteCmdArg(resource));
            }

            if ((modes & OAuthAuthenticationModes.Browser) != 0)
            {
                promptArgs.Append(" --browser");
            }

            if ((modes & OAuthAuthenticationModes.DeviceCode) != 0)
            {
                promptArgs.Append(" --device-code");
            }

            IDictionary<string, string> resultDict = await InvokeHelperAsync(command, promptArgs.ToString());

            if (!resultDict.TryGetValue("mode", out string responseMode))
            {
                throw new Trace2Exception(Context.Trace2, "Missing 'mode' in response");
            }

            switch (responseMode.ToLowerInvariant())
            {
                case "browser":
                    return OAuthAuthenticationModes.Browser;

                case "devicecode":
                    return OAuthAuthenticationModes.DeviceCode;

                default:
                    throw new Trace2Exception(Context.Trace2,
                        $"Unknown mode value in response '{responseMode}'");
            }
        }

        public async Task<OAuth2TokenResult> GetTokenByBrowserAsync(OAuth2Client client, string[] scopes)
        {

View on GitHub (pinned to e8ce762cd0)