{"record":{"id":"6ee91f5fe6c0ea33","repo":"kovidgoyal/kitty","slug":"failed-to-query-terminal-using-tiocgwinsz-with-err","errorCode":null,"errorMessage":"Failed to query terminal using TIOCGWINSZ with error: %w","messagePattern":"Failed to query terminal using TIOCGWINSZ with error: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kittens/icat/main.go","lineNumber":190,"sourceCode":"\tif err != nil {\n\t\treturn 1, err\n\t}\n\terr = parse_mirror()\n\tif err != nil {\n\t\treturn 1, err\n\t}\n\tif opts.UseWindowSize == \"\" {\n\t\tif tty.IsTerminal(os.Stdout.Fd()) {\n\t\t\tscreen_size, err = tty.GetSize(int(os.Stdout.Fd()))\n\t\t} else {\n\t\t\tt, oerr := tty.OpenControllingTerm()\n\t\t\tif oerr != nil {\n\t\t\t\treturn 1, fmt.Errorf(\"Failed to open controlling terminal with error: %w\", oerr)\n\t\t\t}\n\t\t\tscreen_size, err = t.GetSize()\n\t\t}\n\t\tif err != nil {\n\t\t\treturn 1, fmt.Errorf(\"Failed to query terminal using TIOCGWINSZ with error: %w\", err)\n\t\t}\n\t} else {\n\t\tparts := strings.SplitN(opts.UseWindowSize, \",\", 4)\n\t\tif len(parts) != 4 {\n\t\t\treturn 1, fmt.Errorf(\"Invalid size specification: %s\", opts.UseWindowSize)\n\t\t}\n\t\tscreen_size = &unix.Winsize{}\n\t\tvar t uint64\n\t\tif t, err = strconv.ParseUint(parts[0], 10, 16); err != nil || t < 1 {\n\t\t\treturn 1, fmt.Errorf(\"Invalid size specification: %s with error: %w\", opts.UseWindowSize, err)\n\t\t}\n\t\tscreen_size.Col = uint16(t)\n\t\tif t, err = strconv.ParseUint(parts[1], 10, 16); err != nil || t < 1 {\n\t\t\treturn 1, fmt.Errorf(\"Invalid size specification: %s with error: %w\", opts.UseWindowSize, err)\n\t\t}\n\t\tscreen_size.Row = uint16(t)\n\t\tif t, err = strconv.ParseUint(parts[2], 10, 16); err != nil || t < 1 {\n\t\t\treturn 1, fmt.Errorf(\"Invalid size specification: %s with error: %w\", opts.UseWindowSize, err)","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kittens/icat/main.go#L172-L208","documentation":"After obtaining a tty fd (stdout fd or /dev/tty), the TIOCGWINSZ ioctl to read window size failed. The open succeeded but the size query itself returned an error.","triggerScenarios":"The opened fd does not refer to a terminal device (e.g. redirected fd, pty closed mid-run), so ioctl fails with ENOTTY/EINVAL.","commonSituations":"stdout redirected to a file while /dev/tty resolves to something non-queryable; race where the pty closes; exotic terminal multiplexers.","solutions":["Run with stdout connected to the kitty terminal","Pass --use-window-size with an explicit W,H,cell_w,cell_h spec instead","Retry in a fresh terminal if the pty was closed mid-session"],"exampleFix":"# before\nkitty +kitten icat img.png | tee log\n# after\nkitty +kitten icat --use-window-size 120,32,7,14 img.png | tee log","handlingStrategy":"fallback","validationCode":"ws, err := tty.GetSize(fd)\nif err != nil && !tty.IsTerminal(fd) { /* use explicit --use-window-size */ }","typeGuard":null,"tryCatchPattern":"Wrap GetSize; on failure retry once, then fall back to a --use-window-size spec or sane defaults.","preventionTips":["Avoid redirecting icat stdout away from the pty","Close ptys only after icat finishes"],"tags":["kitty","icat","tty","tiocgwinsz"],"backgroundTag":"tty-size-query-failed","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}