{"record":{"id":"213f00e68157e19a","repo":"git-ecosystem/git-credential-manager","slug":"failed-to-enter-raw-console-mode-on-consoleinname","errorCode":null,"errorMessage":"Failed to enter raw console mode on {ConsoleInName}.","messagePattern":"Failed to enter raw console mode on (.+?)\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/Core/Interop/Windows/WindowsAnsiConsoleInput.cs","lineNumber":105,"sourceCode":"\n        // The console is left in its normal (cooked) mode except during an\n        // active keystroke read (see ReadKey). That is what keeps Ctrl+C working\n        // when GCM is doing other work — MSAL polling, a GUI, the network — and\n        // not just while a Spectre prompt happens to be reading: with\n        // ProcessedInput on, Ctrl+C raises CTRL_C_EVENT and the runtime's\n        // default handler terminates the process.\n    }\n\n    // Switch the console into raw mode (no echo, no line input, no system Ctrl+C\n    // handling) for the duration of a read. Caller must hold _modeLock.\n    private void EnterRawMode()\n    {\n        ConsoleMode rawMode = _originalMode\n            & ~(ConsoleMode.LineInput | ConsoleMode.EchoInput | ConsoleMode.ProcessedInput);\n\n        if (!Kernel32.SetConsoleMode(_handle, rawMode))\n        {\n            throw new IOException($\"Failed to enter raw console mode on {ConsoleInName}.\");\n        }\n\n        _inRawMode = true;\n    }\n\n    // Restore the original (cooked) console mode after a read. Idempotent.\n    // Caller must hold _modeLock.\n    private void RestoreMode()\n    {\n        if (!_inRawMode)\n        {\n            return;\n        }\n\n        if (!_handle.IsInvalid && !_handle.IsClosed)\n        {\n            Kernel32.SetConsoleMode(_handle, _originalMode);\n        }","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/Interop/Windows/WindowsAnsiConsoleInput.cs#L87-L123","documentation":"EnterRawMode strips LineInput, EchoInput, and ProcessedInput from the saved console mode via Kernel32.SetConsoleMode so keystrokes (Ctrl+C, arrows) reach GCM unprocessed. If SetConsoleMode fails, it throws IOException because raw-mode reads cannot be performed reliably on the handle.","triggerScenarios":"Calling AcquireRawMode (during a keystroke read) when SetConsoleMode on the CONIN$ handle returns false — the handle lost console status, was closed by another thread, or the console host rejected the mode change.","commonSituations":"Terminal host (ConPTY-based emulators, some IDE terminals) rejecting mode changes; the input handle invalidated between open and raw-mode entry; running under process wrappers that intercept console APIs; rare Windows console substitution.","solutions":["Retry the credential prompt in a standard console (Windows Terminal or conhost).","Avoid wrapper layers that proxy console handles; run git directly or use winpty.","Fall back to non-raw authentication: GCM_INTERACTIVE=never plus a pre-provisioned credential store.","If reproducible, check Windows/console-emulator version and update the terminal emulator."],"exampleFix":"// before\n// IDE embedded terminal intercepting CONIN$\n// after\n// run from Windows Terminal, or:\nset GCM_INTERACTIVE=never","handlingStrategy":"try-catch","validationCode":"if (!Kernel32.GetConsoleMode(h, out var m)) return false; // can't even read mode\nif ((m & (ConsoleMode.LineInput | ConsoleMode.EchoInput)) == 0) return false;","typeGuard":"static bool SupportsRawMode(SafeFileHandle h) =>\n    Kernel32.GetConsoleMode(h, out var mode) &&\n    Kernel32.SetConsoleMode(h, mode) && Kernel32.SetConsoleMode(h, mode);","tryCatchPattern":"try { input.AcquireRawMode(); ... }\ncatch (IOException ex) when (ex.Message.Contains(\"raw console mode\"))\n{ logger.Warn(\"Raw mode unavailable; using line-based input or fallback store.\"); }","preventionTips":["Avoid IDE-embedded or ConPTY wrappers known to reject SetConsoleMode; test in Windows Terminal.","Keep the input handle exclusively owned by the reader thread.","Provide a line-based prompt fallback when raw mode fails.","Update terminal emulator if raw-mode failures are reproducible."],"tags":["windows","console","raw-mode","terminal"],"backgroundTag":"invalid-state-transition","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"}