{"record":{"id":"498091b0a8f15023","repo":"pranshuparmar/witr","slug":"unexpected-ps-output-format-for-pid-d-got-d-fie","errorCode":null,"errorMessage":"unexpected ps output format for pid %d: got %d fields in %q","messagePattern":"unexpected ps output format for pid (.+?): got (.+?) fields in %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/proc/process_freebsd.go","lineNumber":45,"sourceCode":"\t// The display name is derived from args instead.\n\tcmd := exec.Command(\"ps\", \"-p\", pidStr,\n\t\t\"-o\", \"pid=\", \"-o\", \"ppid=\", \"-o\", \"uid=\", \"-o\", \"jid=\",\n\t\t\"-o\", \"state=\", \"-o\", \"pcpu=\", \"-o\", \"rss=\",\n\t\t\"-o\", \"lstart=\", \"-o\", \"args=\")\n\tcmd.Env = buildEnvForPS()\n\tout, err := cmd.Output()\n\tif err != nil {\n\t\treturn model.Process{}, fmt.Errorf(\"process %d not found: %w\", pid, err)\n\t}\n\n\tline := strings.TrimSpace(string(out))\n\tif line == \"\" {\n\t\treturn model.Process{}, fmt.Errorf(\"process %d not found\", pid)\n\t}\n\n\tfields := strings.Fields(line)\n\tif len(fields) < 12 {\n\t\treturn model.Process{}, fmt.Errorf(\"unexpected ps output format for pid %d: got %d fields in %q\", pid, len(fields), line)\n\t}\n\n\tppid, _ := strconv.Atoi(fields[1])\n\tuid, _ := strconv.Atoi(fields[2])\n\tjid := fields[3]\n\tstate := fields[4]\n\tcpuPct, _ := strconv.ParseFloat(fields[5], 64)\n\trssKB, _ := strconv.ParseFloat(fields[6], 64)\n\n\tlstartStr := strings.Join(fields[7:12], \" \")\n\tstartedAt := parseLstart(lstartStr)\n\tif startedAt.IsZero() {\n\t\tstartedAt = time.Now().UTC()\n\t}\n\n\trawCmdline := \"\"\n\tif len(fields) > 12 {\n\t\trawCmdline = strings.Join(fields[12:], \" \")","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/pranshuparmar/witr/blob/dc4fa1da82d3e266fcbd928641b4f30b3077c64f/internal/proc/process_freebsd.go#L27-L63","documentation":"FreeBSD ReadProcess expects a fixed ps column layout (pid ppid uid jid state pcpu rss lstart(5 fields) args...) requiring at least 12 fields. When fewer fields arrive, parsing aborts with this error, which helpfully includes the actual field count and the raw line to diagnose format drift.","triggerScenarios":"ReadProcess receiving ps output with < 12 whitespace-separated fields — a non-standard ps (BusyBox/toybox), a shimmed or wrapper ps in PATH, or a ps that truncates/ignores the -o spec.","commonSituations":"Minimal FreeBSD environments with alternate ps implementations; ps aliased/wrapped in shell profiles; output corruption or locale changes altering the lstart columns.","solutions":["Run `ps -p <pid> -o pid= -o ppid= -o uid= -o jid= -o state= -o pcpu= -o rss= -o lstart= -o args=` manually and compare against the expected 12+ field layout.","Ensure the system ps (/bin/ps) is used — remove wrappers/shims from PATH.","Run with a standard locale (LC_ALL=C) to rule out localization effects.","Use the got-N-fields and raw line in the message to identify which column is missing and report/patch accordingly."],"exampleFix":"# before (diagnose)\nps -p 1234 -o pid= -o ppid= -o uid= -o jid= -o state= -o pcpu= -o rss= -o lstart= -o args=\n# after (force standard env)\nLC_ALL=C /bin/ps -p 1234 -o pid= -o ppid= -o uid= -o jid= -o state= -o pcpu= -o rss= -o lstart= -o args=","handlingStrategy":"validation","validationCode":"// FreeBSD: verify expected 12+ field layout once at startup\nout, _ := exec.Command(\"ps\", \"-p\", \"1\", \"-o\", \"pid=\", \"-o\", \"ppid=\", \"-o\", \"uid=\", \"-o\", \"jid=\", \"-o\", \"state=\", \"-o\", \"pcpu=\", \"-o\", \"rss=\", \"-o\", \"lstart=\", \"-o\", \"args=\").Output()\nif out != nil && len(strings.Fields(strings.TrimSpace(string(out)))) < 12 {\n    // non-standard ps output detected\n}","typeGuard":null,"tryCatchPattern":"proc, err := proc.ReadProcess(pid)\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected ps output format\") {\n        // log err fully: it includes field count and raw line for diagnosis\n    }\n}","preventionTips":["Keep LC_ALL=C when spawning ps for parsing","Ensure /bin/ps is the real system ps (no shims in PATH)","Use the error's embedded raw line to detect format drift early","Pin/test the ps column layout on all target FreeBSD versions"],"tags":["freebsd","ps-output-parsing","environment"],"backgroundTag":"unexpected-ps-output-format","analyzedSha":"dc4fa1da82d3e266fcbd928641b4f30b3077c64f","analyzedAt":"2026-09-01T12:17:08.767Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}