{"record":{"id":"6cb03d40d7fcd0ad","repo":"JanDeDobbeleer/oh-my-posh","slug":"terminal-width-must-be-greater-than-zero","errorCode":null,"errorMessage":"terminal width must be greater than zero","messagePattern":"terminal width must be greater than zero","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/runtime/terminal_unix.go","lineNumber":90,"sourceCode":"\t}\n\n\tterm.CmdFlags.TerminalWidth = int(width)\n\tlog.Debugf(\"terminal width: %d\", term.CmdFlags.TerminalWidth)\n\n\treturn term.CmdFlags.TerminalWidth, err\n}\n\nfunc resolveTerminalWidth(width uint, terminalErr error, columns string) (uint, error) {\n\tif width != 0 {\n\t\treturn width, terminalErr\n\t}\n\n\tcolumnWidth, err := strconv.Atoi(columns)\n\tif err != nil {\n\t\treturn 0, errors.Join(terminalErr, err)\n\t}\n\tif columnWidth <= 0 {\n\t\treturn 0, errors.Join(terminalErr, errors.New(\"terminal width must be greater than zero\"))\n\t}\n\n\treturn uint(columnWidth), nil\n}\n\nfunc (term *Terminal) Platform() string {\n\tconst key = \"environment_platform\"\n\tif val, found := cache.Device.Get[string](key); found {\n\t\treturn val\n\t}\n\n\tvar platform string\n\tdefer func() {\n\t\tcache.Device.Set(key, platform, cache.INFINITE)\n\t}()\n\n\tif wsl := term.Getenv(\"WSL_DISTRO_NAME\"); len(wsl) != 0 {\n\t\tplatform, _, _ = strings.Cut(wsl, \"-\")","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/runtime/terminal_unix.go#L72-L108","documentation":"resolveTerminalWidth parses the COLUMNS environment variable (via the shell) into a terminal width. The shared terminalErr covers failures, and this specific error is joined onto it when the parsed value is zero or negative, since a non-positive width would break prompt rendering math. It means the width source supplied a nonsensical value.","triggerScenarios":"TerminalWidth (or an anonymous helper wrapping it) read a COLUMNS value that parsed to <= 0, e.g. COLUMNS=0 or COLUMNS=-1, on unix systems.","commonSituations":"Non-interactive shells or CI environments exporting COLUMNS=0; badly configured shell startup scripts exporting COLUMNS; tmux/screen edge cases; running under a wrapper that fakes terminal size.","solutions":["Check the COLUMNS value in the shell where the prompt renders: `echo $COLUMNS` — unset or fix it if 0/negative.","Remove any `export COLUMNS=...` from shell startup files that sets a bogus value.","Run the prompt in a real TTY so COLUMNS reflects actual terminal size.","Update oh-my-posh if you need different fallback behavior for missing/invalid COLUMNS."],"exampleFix":"// before (shell rc)\nexport COLUMNS=0\n// after: let oh-my-posh/tput detect width, or set a positive value\nexport COLUMNS=120","handlingStrategy":"validation","validationCode":"// validate before rendering\ncols := os.Getenv(\"COLUMNS\")\nif n, err := strconv.Atoi(cols); err != nil || n <= 0 {\n    cols = \"80\" // safe fallback\n}","typeGuard":"func validWidth(s string) bool {\n    n, err := strconv.Atoi(s)\n    return err == nil && n > 0\n}","tryCatchPattern":"w, err := term.TerminalWidth()\nif err != nil {\n    w = 80 // default width fallback\n}","preventionTips":["Never export COLUMNS=0 or negative values in shell startup files.","Verify `echo $COLUMNS` in the shell used for prompt rendering.","Render in a real TTY so COLUMNS reflects the actual terminal size."],"tags":["terminal","width","unix","environment"],"backgroundTag":"invalid-terminal-width","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}