{"record":{"id":"7c2609433a909c3f","repo":"git-ecosystem/git-credential-manager","slug":"missing-mode-in-response-7c2609","errorCode":null,"errorMessage":"Missing 'mode' in response","messagePattern":"Missing 'mode' in response","errorType":"exception","errorClass":"Trace2Exception","httpStatus":null,"severity":"error","filePath":"src/GitLab/GitLabAuthentication.cs","lineNumber":219,"sourceCode":"        {\n            var promptArgs = new StringBuilder(args);\n            promptArgs.Append(\"prompt\");\n            if (!string.IsNullOrWhiteSpace(userName))\n            {\n                promptArgs.AppendFormat(\" --username {0}\", QuoteCmdArg(userName));\n            }\n\n            promptArgs.AppendFormat(\" --url {0}\", QuoteCmdArg(targetUri.ToString()));\n\n            if ((modes & AuthenticationModes.Basic) != 0) promptArgs.Append(\" --basic\");\n            if ((modes & AuthenticationModes.Browser) != 0) promptArgs.Append(\" --browser\");\n            if ((modes & AuthenticationModes.Pat) != 0) promptArgs.Append(\" --pat\");\n\n            IDictionary<string, string> resultDict = await InvokeHelperAsync(helperCommand, promptArgs.ToString());\n\n            if (!resultDict.TryGetValue(\"mode\", out string responseMode))\n            {\n                throw new Trace2Exception(Context.Trace2, \"Missing 'mode' in response\");\n            }\n\n            switch (responseMode.ToLowerInvariant())\n            {\n                case \"pat\":\n                    if (!resultDict.TryGetValue(\"pat\", out string pat))\n                    {\n                        throw new Trace2Exception(Context.Trace2, \"Missing 'pat' in response\");\n                    }\n\n                    if (!resultDict.TryGetValue(\"username\", out string patUserName))\n                    {\n                        // Username is optional for PATs\n                    }\n\n                    return new AuthenticationPromptResult(\n                        AuthenticationModes.Pat, new GitCredential(patUserName, pat));\n","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/GitLab/GitLabAuthentication.cs#L201-L237","documentation":"Thrown by GetAuthenticationViaHelperAsync in GitLabAuthentication when the external Git credential helper command returns a result dictionary that does not contain a 'mode' key. The helper protocol requires every response to declare its authentication mode (pat, browser, or basic); without it GCM cannot decide how to proceed and fails fast with a Trace2Exception.","triggerScenarios":"Running `git-credential-manager gitlab` (GetAuthenticationAsync -> GetAuthenticationViaHelperAsync) where the configured helper executable (GitLabHelper.Command setting, e.g. a custom script) exits successfully but emits output without a `mode=` line.","commonSituations":"Custom or third-party GitLab credential helpers that print only a token; outdated helper scripts written for an older protocol; helper output parsed incorrectly due to extra logging polluting stdout.","solutions":["Update or fix the configured GitLab credential helper so it emits `mode=` (one of pat, browser, basic) in its output.","Check the helper command configured via `credential.gitLabHelper` / GCM_GITLAB_HELPER and remove any broken override so GCM falls back to its built-in UI flow.","Inspect helper stdout for stray log lines that break key=value parsing; redirect logging to stderr."],"exampleFix":"// before (helper script output)\necho \"pat=ghp_xxx\"\n// after\necho \"mode=pat\"\necho \"pat=glpat_xxx\"","handlingStrategy":"validation","validationCode":"// Validate helper output before relying on it\nclass HelperResponseValidator {\n  static bool HasMode(IDictionary<string, string> result) =>\n    result != null && result.ContainsKey(\"mode\") &&\n    new[] { \"pat\", \"browser\", \"basic\" }.Contains(result[\"mode\"].ToLowerInvariant());\n}","typeGuard":null,"tryCatchPattern":"try {\n  var result = await auth.GetAuthenticationAsync(...);\n} catch (Trace2Exception ex) when (ex.Message.Contains(\"Missing 'mode' in response\")) {\n  // fall back to built-in UI flow or prompt user to fix the helper\n  logger.Warn(\"GitLab helper returned no mode; using built-in auth\");\n}","preventionTips":["Pin the helper script to the documented GCM helper protocol (mode + fields)","Test custom helpers manually by inspecting their key=value stdout","Avoid printing logs to stdout in helper scripts"],"tags":["gitlab","credential-helper","protocol"],"backgroundTag":"unexpected-response-shape","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"}