{"record":{"id":"68ad7d26ed36e72d","repo":"git-ecosystem/git-credential-manager","slug":"unexpected-interaction-mode","errorCode":null,"errorMessage":"Unexpected interaction mode.","messagePattern":"Unexpected interaction mode\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Core/Authentication/Entra/EntraAuthentication.PublicClient.cs","lineNumber":323,"sourceCode":"                    .WithUseEmbeddedWebView(true)\n                    .WithEmbeddedWebViewOptions(GetEmbeddedWebViewOptions())\n                    .ExecuteAsync(ct);\n\n            case InteractionMode.SystemWebView:\n                Context.Trace.WriteLine(\"Performing interactive authentication via system webview...\");\n                Context.Console.WriteInfo(\"opening browser to complete authentication...\");\n                return await app.AcquireTokenInteractive(scopes)\n                    .WithUseEmbeddedWebView(false)\n                    .WithSystemWebViewOptions(GetSystemWebViewOptions())\n                    .ExecuteAsync(ct);\n\n            case InteractionMode.DeviceCode:\n                Context.Trace.WriteLine(\"Performing interactive authentication via device code...\");\n                return await app.AcquireTokenWithDeviceCode(scopes, ShowDeviceCodeAsync)\n                    .ExecuteAsync(ct);\n\n            default:\n                throw new ArgumentOutOfRangeException(nameof(interactionMode), interactionMode, \"Unexpected interaction mode.\");\n        }\n    }\n\n    private async Task<bool> UseDefaultAccountAsync(string userName, CancellationToken ct)\n    {\n        ThrowIfUserInteractionDisabled();\n\n        if (Context.SessionManager.IsDesktopSession && Context.Settings.IsGuiPromptsEnabled)\n        {\n            if (TryFindHelperCommand(out string command, out string args))\n            {\n                var sb = new StringBuilder(args);\n                sb.Append(\"default-account\");\n                sb.AppendFormat(\" --username {0}\", QuoteCmdArg(userName));\n\n                IDictionary<string, string> result = await InvokeHelperAsync(command, sb.ToString());\n\n                if (result.TryGetValue(\"use_default_account\", out string str) && !string.IsNullOrWhiteSpace(str))","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/Authentication/Entra/EntraAuthentication.PublicClient.cs#L305-L341","documentation":"Thrown as the default case of the interaction mode switch in GetTokenForUserInteractiveAsync. The InteractionMode value passed in did not match Auto, EmbeddedWebView, SystemWebView, or DeviceCode, meaning an out-of-range or unknown enum value reached the method. This is an argument validation guard against enum values the switch does not handle.","triggerScenarios":"Calling GetTokenForUserAsync (or GetTokenForUserInteractiveAsync) with an explicit interactionMode argument that is not a defined/handled InteractionMode value — typically from an unvalidated cast of an int/setting string to the enum.","commonSituations":"User sets an invalid value in configuration (e.g. GCM interaction setting parsed into an out-of-range enum value), a caller casts a raw integer to InteractionMode without validating, or a newer enum member is passed to an older build.","solutions":["Pass only valid InteractionMode values: Auto, EmbeddedWebView, SystemWebView, or DeviceCode.","If the mode comes from config, validate/parse it defensively and fall back to InteractionMode.Auto on unrecognized values.","Check for version skew: a mode defined in a newer library version cannot be used with an older build; update the library."],"exampleFix":"// before\nvar mode = (InteractionMode)int.Parse(configValue);\nawait GetTokenForUserAsync(scopes, mode);\n// after\nvar mode = Enum.TryParse<InteractionMode>(configValue, out var m) && m is InteractionMode.Auto or InteractionMode.DeviceCode or InteractionMode.SystemWebView or InteractionMode.EmbeddedWebView ? m : InteractionMode.Auto;\nawait GetTokenForUserAsync(scopes, mode);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(InteractionMode), mode)) mode = InteractionMode.Auto;","typeGuard":"static bool IsValidInteractionMode(InteractionMode mode) =>\n    mode is InteractionMode.Auto or InteractionMode.EmbeddedWebView\n        or InteractionMode.SystemWebView or InteractionMode.DeviceCode;","tryCatchPattern":"try\n{\n    token = await auth.GetTokenForUserAsync(scopes, mode);\n}\ncatch (ArgumentOutOfRangeException ex)\n{\n    // invalid mode value from config; retry with Auto\n    token = await auth.GetTokenForUserAsync(scopes, InteractionMode.Auto);\n}","preventionTips":["Never cast raw ints/strings to InteractionMode without Enum.TryParse/IsDefined.","Validate config-driven interaction settings at startup with a fallback to Auto.","Keep library versions in sync when new enum values are introduced."],"tags":["argument-out-of-range","enum","authentication","configuration"],"backgroundTag":"argument-out-of-range","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"}