{"record":{"id":"584898d7b4ea3903","repo":"gravitational/teleport","slug":"failed-to-set-stdout-mode-w","errorCode":null,"errorMessage":"failed to set stdout mode: %w","messagePattern":"failed to set stdout mode: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/client/terminal/terminal_windows.go","lineNumber":61,"sourceCode":"func initTerminal(input bool) (func(), error) {\n\tstdoutFd := int(syscall.Stdout)\n\tstdinFd := int(syscall.Stdin)\n\n\toldOutMode, err := winterm.GetConsoleMode(uintptr(stdoutFd))\n\tif err != nil {\n\t\treturn func() {}, fmt.Errorf(\"failed to retrieve stdout mode: %w\", err)\n\t}\n\n\toldInMode, err := winterm.GetConsoleMode(uintptr(stdinFd))\n\tif err != nil {\n\t\treturn func() {}, fmt.Errorf(\"failed to retrieve stdout mode: %w\", err)\n\t}\n\n\tnewOutMode := oldOutMode | winterm.ENABLE_VIRTUAL_TERMINAL_PROCESSING | winterm.DISABLE_NEWLINE_AUTO_RETURN\n\n\terr = winterm.SetConsoleMode(uintptr(stdoutFd), newOutMode)\n\tif err != nil {\n\t\treturn func() {}, fmt.Errorf(\"failed to set stdout mode: %w\", err)\n\t}\n\n\tif input {\n\t\tnewInMode := oldInMode\n\t\tnewInMode &^= winterm.ENABLE_ECHO_INPUT\n\t\tnewInMode &^= winterm.ENABLE_LINE_INPUT\n\t\tnewInMode &^= winterm.ENABLE_MOUSE_INPUT\n\t\tnewInMode &^= winterm.ENABLE_WINDOW_INPUT\n\t\tnewInMode &^= winterm.ENABLE_PROCESSED_INPUT\n\n\t\tnewInMode |= winterm.ENABLE_EXTENDED_FLAGS\n\t\tnewInMode |= winterm.ENABLE_INSERT_MODE\n\t\tnewInMode |= winterm.ENABLE_QUICK_EDIT_MODE\n\t\tnewInMode |= winterm.ENABLE_VIRTUAL_TERMINAL_INPUT\n\n\t\terr = winterm.SetConsoleMode(uintptr(stdinFd), newInMode)\n\t\tif err != nil {\n\t\t\t// Attempt to reset the stdout mode before returning.","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/gravitational/teleport/blob/1283425b60ec5f60d509ba4c791183d452923ff7/lib/client/terminal/terminal_windows.go#L43-L79","documentation":"After computing the new output mode (ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN), initTerminal calls winterm.SetConsoleMode on the stdout handle. If the Windows console API rejects the new mode, this wrapped error is returned. The console buffer exists but refuses the requested mode flags.","triggerScenarios":"Calling Terminal.InitRaw on Windows when SetConsoleMode(stdout, newOutMode) fails: the console host does not support ENABLE_VIRTUAL_TERMINAL_PROCESSING (legacy conhost pre-Windows-10-1607), the stdout handle is a console in an incompatible state, or the handle lacks permission to change its mode.","commonSituations":"Running on old Windows 10 builds (VT processing was opt-in before 1607) or legacy terminals where the flag is unsupported; running inside environments emulating a console (some CI agents, remote shells) that reject the flag; group-policy or terminal-software restricting console mode changes.","solutions":["Update Windows to a build supporting virtual terminal processing (Windows 10 1607+), or run inside Windows Terminal.","Pre-check support: attempt GetConsoleMode on stdout; if SetConsoleMode with ENABLE_VIRTUAL_TERMINAL_PROCESSING fails, fall back to a non-VT rendering path or degrade gracefully instead of failing the session.","Ensure stdout is a genuine console buffer handle, not a wrapped/emulated handle provided by the host environment.","If the error persists in a specific terminal emulator, test in plain conhost to isolate emulator-specific restrictions."],"exampleFix":"// before\ncleanup, err := term.InitRaw(false)\nif err != nil {\n    return trace.Wrap(err)\n}\n\n// after\ncleanup, err := term.InitRaw(false)\nif err != nil {\n    log.Warnf(\"VT output mode unavailable (%v); continuing without raw output\", err)\n    cleanup = func() {}\n}","handlingStrategy":"fallback","validationCode":"// Probe VT support before entering a real session:\nmode, err := winterm.GetConsoleMode(uintptr(syscall.Stdout))\nif err != nil {\n    return errors.New(\"no console on stdout; VT output unavailable\")\n}\nif err := winterm.SetConsoleMode(uintptr(syscall.Stdout), mode|winterm.ENABLE_VIRTUAL_TERMINAL_PROCESSING); err != nil {\n    return errors.New(\"console host does not support VT processing\")\n}\nwinterm.SetConsoleMode(uintptr(syscall.Stdout), mode) // restore","typeGuard":"func vtOutputSupported() bool {\n    mode, err := winterm.GetConsoleMode(uintptr(syscall.Stdout))\n    if err != nil {\n        return false\n    }\n    return winterm.SetConsoleMode(uintptr(syscall.Stdout), mode|winterm.ENABLE_VIRTUAL_TERMINAL_PROCESSING) == nil\n}","tryCatchPattern":"cleanup, err := t.InitRaw(input)\nif err != nil && strings.Contains(err.Error(), \"failed to set stdout mode\") {\n    log.Warn(\"VT output mode rejected; continuing without raw output\")\n    cleanup = func() {}\n    return nil\n}","preventionTips":["Target Windows 10 1607+ or Windows Terminal where ENABLE_VIRTUAL_TERMINAL_PROCESSING is supported.","Add a startup VT-capability probe and a non-VT rendering fallback path.","Test on legacy conhost in addition to Windows Terminal when supporting older environments."],"tags":["windows","terminal","vt100","console-api"],"backgroundTag":"set-console-mode-failed","analyzedSha":"1283425b60ec5f60d509ba4c791183d452923ff7","analyzedAt":"2026-09-02T04:06:41.601Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}