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

Unknown authentication mode

Error message

Unknown authentication mode

What it means

After the dialog returns, ExecuteAsync switches on viewModel.SelectedMode and writes the credential result. An unrecognized mode falls into the default case, throwing ArgumentOutOfRangeException("Unknown authentication mode") — an internal invariant violation meaning the AuthenticationModes enum gained a value the command does not handle.

Solutions

  1. Upgrade or reinstall git-credential-manager so the UI and command code are from the same version.
  2. If you build from source, add a case for the new AuthenticationModes value in CredentialsCommand.ExecuteAsync.
  3. Report a bug with trace2 logs if it occurs on an unmodified release build.

Example fix

// before
default:
    throw new ArgumentOutOfRangeException(nameof(AuthenticationModes), "Unknown authentication mode", viewModel.SelectedMode.ToString());
// after: handle the new mode explicitly
case AuthenticationModes.BearerToken:
    WriteResult(new Dictionary<string, string> { ["password"] = viewModel.Token });
    break;
Defensive patterns

Strategy: try-catch

Type guard

Enum.IsDefined(typeof(AuthenticationModes), viewModel.SelectedMode)

Try / catch

try { await command.ExecuteAsync(input); } catch (ArgumentOutOfRangeException ex) when (ex.Message.Contains("Unknown authentication mode")) { /* upgrade GCM or report bug with trace2 logs */ }

Prevention

When it happens

Trigger: viewModel.SelectedMode contains a value not covered by the handled AuthenticationModes cases (OAuth, Basic, etc.) — usually only possible when the enum and the switch are out of sync after a code change, or corrupted state.

Common situations: Developers adding a new AuthenticationModes member without updating CredentialsCommand's switch; users on mismatched GCM builds/plugins; bespoke forks extending the enum.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at src/Atlassian.Bitbucket/UI/Commands/CredentialsCommand.cs:69

            {
                case AuthenticationModes.OAuth:
                    WriteResult(new Dictionary<string, string>
                    {
                        ["mode"] = "oauth"
                    });
                    break;

                case AuthenticationModes.Basic:
                    WriteResult(new Dictionary<string, string>
                    {
                        ["mode"] = "basic",
                        ["username"] = viewModel.UserName,
                        ["password"] = viewModel.Password,
                    });
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(AuthenticationModes),
                        "Unknown authentication mode", viewModel.SelectedMode.ToString());
            }

            return 0;
        }

        protected abstract Task ShowAsync(CredentialsViewModel viewModel, CancellationToken ct);
    }
}

View on GitHub (pinned to e8ce762cd0)