{"record":{"id":"220c0d234d502372","repo":"abiosoft/colima","slug":"error-getting-terminal-size-w","errorCode":null,"errorMessage":"error getting terminal size: %w","messagePattern":"error getting terminal size: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"util/terminal/output.go","lineNumber":151,"sourceCode":"}\n\nfunc (v *verboseWriter) clearScreen() {\n\tfor i := 0; i < v.screenHeight; i++ {\n\t\tClearLine()\n\t}\n\tv.screenHeight = 0\n}\n\nfunc (v *verboseWriter) updateTerm() error {\n\t// no need to refresh so quickly\n\tif time.Since(v.lastUpdate) < time.Second*2 {\n\t\treturn nil\n\t}\n\tv.lastUpdate = time.Now().UTC()\n\n\tw, _, err := term.GetSize(int(os.Stdout.Fd()))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error getting terminal size: %w\", err)\n\t}\n\t// A width of zero would result in a division by zero panic when computing overflow\n\t// in printScreen. Therefore, set it to a safe - even though probably wrong - value.\n\t// We use <= 0 here because negative values are guaranteed to lead to unexpected\n\t// results, even if they don't cause panics.\n\tif w <= 0 {\n\t\tw = 80\n\t}\n\tv.termWidth = w\n\n\treturn nil\n}\n\nfunc countDisplayLines(line string, termWidth int) int {\n\tif termWidth <= 0 {\n\t\ttermWidth = 80\n\t}\n","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/util/terminal/output.go#L133-L169","documentation":"verboseWriter.updateTerm (util/terminal/output.go:151) queries the terminal size via term.GetSize(os.Stdout.Fd()), throttled to once per 2 seconds; the wrapped error is almost always ENOTTY because stdout is not a terminal. printScreen (output.go:121) propagates the error, so the verbose live-view renderer aborts instead of drawing. A width<=0 case is already defended separately (falls back to 80), so the error path is specifically the ioctl failure.","triggerScenarios":"Running colima with verbose/live output piped or redirected: `colima start --verbose | tee log.txt`, `colima start > out.log`, or colima invoked from CI/daemon contexts where stdout has no controlling terminal.","commonSituations":"Piping colima output for logging in scripts; running colima in CI jobs; capturing output with subprocess pipes; terminal multiplexers that detach the pty mid-run.","solutions":["Run the command directly in an interactive terminal instead of piping","When piping is required, allocate a pty: `script -q /dev/null colima start ... | tee log.txt`","Inspect colima's own logs instead of stdout (e.g. `colima start --verbose` writes to log files under ~/.colima / ~/Library/Logs/colima)","If you embed this writer in your own tool, treat the updateTerm error as non-fatal and keep a default width of 80"],"exampleFix":"// before\nout := v.printScreen() // returns error when stdout is piped, screen never renders\n\n// after\nif err := v.printScreen(); err != nil {\n    // non-tty stdout: fall back to plain printing, don't kill the writer\n    v.termWidth = 80\n}","handlingStrategy":"fallback","validationCode":"// detect non-tty stdout before enabling the live verbose writer\nfunc stdoutIsTTY() bool {\n    return term.IsTerminal(int(os.Stdout.Fd()))\n}","typeGuard":null,"tryCatchPattern":"if err := v.printScreen(); err != nil {\n    // treat terminal-size failure as cosmetic: fall back to width 80 and keep running\n    v.termWidth = 80\n}","preventionTips":["Check term.IsTerminal before installing a terminal-aware writer","Default width to 80 and log at debug level instead of failing","Wrap piped runs in `script -q /dev/null ...` to provide a pty","Send machine-readable output to a file or stderr, not piped stdout"],"tags":["terminal","tty","io","cli"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}