git-ecosystem/git-credential-manager · error · ArgumentOutOfRangeException
Unknown authentication mode
Error message
Unknown authentication mode
What it means
The Bitbucket UI credential prompt switch handles a fixed set of AuthenticationModes values; any mode selected outside the handled cases hits the default branch and throws ArgumentOutOfRangeException with message 'Unknown authentication mode'. This is an internal invariant: the UI should only ever offer supported modes.
Solutions
- Ensure only single, supported modes (Basic, OAuth/Browser, Gcm) are included in the modes set passed to GetCredentialsAsync
- Update Git Credential Manager to matching versions so UI helper and enum definitions agree
- If custom-calling, avoid passing combined flags; pass one mode per prompt
Example fix
// before var result = await auth.GetCredentialsAsync(uri, null, AuthenticationModes.Basic | AuthenticationModes.OAuth | (AuthenticationModes)0x100); // after var result = await auth.GetCredentialsAsync(uri, null, AuthenticationModes.Basic | AuthenticationModes.OAuth);
Defensive patterns
Strategy: validation
Validate before calling
var allowed = new[] { AuthenticationModes.Basic, AuthenticationModes.OAuth, AuthenticationModes.Browser };
if (!allowed.Contains(mode)) throw new InvalidOperationException($"Unsupported mode {mode}"); Type guard
bool IsSupportedMode(AuthenticationModes m) => m is AuthenticationModes.Basic or AuthenticationModes.OAuth or AuthenticationModes.Browser;
Try / catch
try { await auth.GetCredentialsAsync(uri, user, modes); }
catch (ArgumentOutOfRangeException ex) { trace.Error(ex); return null; } Prevention
- Pass single enum values, not arbitrary flag combinations
- Keep GCM and its UI helper on the same version
- Only include modes the host provider documents as supported
When it happens
Trigger: GetCredentialsAsync -> GetCredentialsViaUiAsync when viewModel.SelectedMode holds a mode value not present in the switch's case labels (e.g. an enum value added or combined flags passed through).
Common situations: Version mismatch between GCM components or plugins passing a new/combined AuthenticationModes value; manual construction of CredentialsPromptOptions with an unhandled mode.
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.
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
Related errors
- Unexpected AuthenticationModes returned from prompt
- Unexpected interaction mode.
- At least one AuthenticationModes must be supplied
- Unsupported workload federation scenario.
- No protocol name mapping is defined for the given…
AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11).
Data as JSON: /api/errors/c2e995c6879e51eb.
Report an issue: GitHub.
Appendix: source
Thrown at src/Atlassian.Bitbucket/BitbucketAuthentication.cs:145
}
await AvaloniaUi.ShowViewAsync<CredentialsView>(viewModel, GetParentWindowHandle(), CancellationToken.None);
ThrowIfWindowCancelled(viewModel);
switch (viewModel.SelectedMode)
{
case AuthenticationModes.OAuth:
return new CredentialsPromptResult(AuthenticationModes.OAuth);
case AuthenticationModes.Basic:
return new CredentialsPromptResult(
AuthenticationModes.Basic,
new GitCredential(viewModel.UserName, viewModel.Password)
);
default:
throw new ArgumentOutOfRangeException(nameof(AuthenticationModes),
"Unknown authentication mode", viewModel.SelectedMode.ToString());
}
}
private async Task<CredentialsPromptResult> GetCredentialsViaTtyAsync(Uri targetUri, string userName, AuthenticationModes modes)
{
ThrowIfTerminalPromptsDisabled();
switch (modes)
{
case AuthenticationModes.Basic:
Context.Console.WriteLine($"Enter Bitbucket credentials for '{targetUri}'...");
if (!string.IsNullOrWhiteSpace(userName))
{
// Don't need to prompt for the username if it has been specified already
Context.Console.WriteLine($"Username: {userName}");
}View on GitHub (pinned to e8ce762cd0)