{"record":{"id":"3db9a1b2a605bdc5","repo":"pranshuparmar/witr","slug":"process-d-not-found-w","errorCode":null,"errorMessage":"process %d not found: %w","messagePattern":"process (.+?) not found: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/proc/process_darwin.go","lineNumber":30,"sourceCode":"\t\"time\"\n\n\t\"github.com/pranshuparmar/witr/pkg/model\"\n)\n\nfunc ReadProcess(pid int) (model.Process, error) {\n\tif pid <= 0 {\n\t\treturn model.Process{}, fmt.Errorf(\"invalid pid %d\", pid)\n\t}\n\tpidStr := strconv.Itoa(pid)\n\n\t// Format: pid(0) ppid(1) uid(2) lstart(3-7) state(8) pcpu(9) rss(10) args(11+)\n\t// ucomm is excluded because it can contain spaces (e.g. \"Microsoft Teams\"),\n\t// which breaks strings.Fields parsing. The display name is derived from args instead.\n\tcmd := exec.Command(\"ps\", \"-p\", pidStr, \"-o\", \"pid=,ppid=,uid=,lstart=,state=,pcpu=,rss=,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) < 11 {\n\t\treturn model.Process{}, fmt.Errorf(\"unexpected ps output format for pid %d\", pid)\n\t}\n\n\tppid, _ := strconv.Atoi(fields[1])\n\tuid, _ := strconv.Atoi(fields[2])\n\n\tlstartStr := strings.Join(fields[3:8], \" \")\n\tstartedAt, _ := time.Parse(\"Mon Jan 2 15:04:05 2006\", lstartStr)\n\tif startedAt.IsZero() {","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/pranshuparmar/witr/blob/dc4fa1da82d3e266fcbd928641b4f30b3077c64f/internal/proc/process_darwin.go#L12-L48","documentation":"ReadProcess on macOS runs `ps -p <pid> ...`; when ps exits non-zero (which happens when the PID does not exist) this error wraps the underlying exec error. It is the primary 'process is gone' signal on darwin.","triggerScenarios":"ReadProcess called with a PID that has already terminated (ps exit status 1); also ps failures such as the binary being unavailable or exec permission issues, which surface wrapped in the same message.","commonSituations":"Inspecting a process that exited between discovery and the ReadProcess call; watching a parent that reaped and exited a child; running inside restricted containers where ps is missing.","solutions":["Re-check that the PID exists (`ps -p <pid>`) before retrying; if it exited, the process is gone.","Retry promptly after obtaining the PID to narrow the exit race.","Inspect the wrapped error (%w): 'No such process' means exit; 'executable file not found' means ps is missing in the environment.","Fall back to the platform snapshot or read /proc-like sources if available; or inspect the parent instead."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// macOS: check existence before ReadProcess\nif out, err := exec.Command(\"ps\", \"-p\", strconv.Itoa(pid), \"-o\", \"pid=\").Output(); err != nil || len(strings.TrimSpace(string(out))) == 0 {\n    return fmt.Errorf(\"pid %d not running\", pid)\n}","typeGuard":null,"tryCatchPattern":"proc, err := proc.ReadProcess(pid)\nif err != nil {\n    if strings.Contains(err.Error(), \"not found\") {\n        // process exited between discovery and read: handle as 'gone'\n    } else {\n        // inspect wrapped error for environment issues (ps missing)\n    }\n}","preventionTips":["Minimize delay between obtaining the PID and reading it","Unwrap the error to distinguish process-exit from ps-availability problems","Have a fallback path (snapshot/parent inspection) for exited targets"],"tags":["macos","process-exited","ps"],"backgroundTag":"process-not-found","analyzedSha":"dc4fa1da82d3e266fcbd928641b4f30b3077c64f","analyzedAt":"2026-09-01T12:17:08.767Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}