{"record":{"id":"0f756567fb8591b4","repo":"git-ecosystem/git-credential-manager","slug":"failed-to-enter-raw-terminal-mode","errorCode":null,"errorMessage":"Failed to enter raw terminal mode.","messagePattern":"Failed to enter raw terminal mode\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/Core/Interop/Linux/LinuxAnsiConsoleInput.cs","lineNumber":54,"sourceCode":"            _original = t;\n\n            // Raw mode: disable echo, line buffering, and signal interpretation.\n            // With ISIG off the terminal does not generate SIGINT, so Ctrl+C\n            // arrives as a 0x03 byte that the base adapter reads and acts on\n            // directly. This is robust to GCM not being the terminal's\n            // foreground process group.\n            //\n            // TCSANOW (apply immediately) rather than TCSAFLUSH: this context\n            // is entered and disposed around each keystroke read, so the\n            // terminal is only raw while we are actively reading. Flushing on\n            // every transition would discard typeahead still queued in the tty\n            // buffer (e.g. the trailing Enter of a pasted \"<down><enter>\"),\n            // hanging the next read.\n            t.c_lflag &= ~(LocalFlags.ECHO | LocalFlags.ICANON | LocalFlags.ISIG);\n\n            if (Termios_Linux.tcsetattr(_fd, SetActionFlags.TCSANOW, ref t) != 0)\n            {\n                throw new System.IO.IOException(\"Failed to enter raw terminal mode.\");\n            }\n        }\n\n        public void Dispose()\n        {\n            if (_isDisposed) return;\n            Termios_Linux.tcsetattr(_fd, SetActionFlags.TCSANOW, ref _original);\n            _isDisposed = true;\n        }\n    }\n}\n","sourceCodeStart":36,"sourceCodeEnd":66,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/Interop/Linux/LinuxAnsiConsoleInput.cs#L36-L66","documentation":"RawModeContext's constructor calls tcsetattr to switch the terminal file descriptor into raw mode (echo, canonical processing, and signals disabled). When tcsetattr returns nonzero it throws this IOException, meaning the kernel rejected the termios change and the console input cannot be read in raw mode.","triggerScenarios":"Creating a RawModeContext on a file descriptor that is not an interactive TTY (redirected stdin/stdout, pipes, background process without a controlling terminal), or when the fd is invalid/closed.","commonSituations":"Running the interactive console app with output piped or redirected (e.g. `app > log.txt`), under a non-TTY CI runner, inside Docker without -t, or via SSH with no pty allocated.","solutions":["Ensure stdin/stdout are attached to a real TTY before constructing RawModeContext (check isatty on the fd)","Run the process with a pseudo-terminal: `docker run -t`, `ssh -tt`, or `script -qec` in CI","Fall back to line-based (cooked) console input when raw mode is unavailable","Verify the fd passed to the RawModeContext constructor is valid and open"],"exampleFix":"// before\nusing var raw = new RawModeContext(fd); // throws if fd is not a TTY\n// after\nif (!IsAtty(fd)) { useCookedInput = true; }\nelse using var raw = new RawModeContext(fd);","handlingStrategy":"try-catch","validationCode":"[DllImport(\"libc\")] static extern int isatty(int fd);\nif (isatty(fd) == 0) throw new InvalidOperationException(\"Raw mode requires a TTY\");","typeGuard":"bool CanUseRawMode(int fd) => isatty(fd) != 0;","tryCatchPattern":"try { using var raw = new RawModeContext(fd); /* read keys */ }\ncatch (System.IO.IOException ex) when (ex.Message.Contains(\"raw terminal\")) { FallBackToCookedInput(); }","preventionTips":["Always run interactive console features with an attached TTY (docker -t, ssh -tt)","Check isatty before enabling raw mode","Provide a cooked-mode fallback for non-interactive environments","Test console features in CI with a pseudo-TTY if they must run there"],"tags":["terminal","linux","tty","interop"],"backgroundTag":"unsupported-platform","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"}