{"record":{"id":"fa2d94489faff6c8","repo":"abiosoft/colima","slug":"invalid-pid-v","errorCode":null,"errorMessage":"invalid pid: %v","messagePattern":"invalid pid: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/daemon/daemon.go","lineNumber":125,"sourceCode":"\t\t}\n\t}\n\n}\n\nfunc status() error {\n\tinfo := Info()\n\tif _, err := os.Stat(info.PidFile); err != nil {\n\t\treturn fmt.Errorf(\"pid file not found: %w\", err)\n\t}\n\n\t// check if process is actually running\n\tp, err := os.ReadFile(info.PidFile)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error reading pid file: %w\", err)\n\t}\n\tpid, _ := strconv.Atoi(string(p))\n\tif pid == 0 {\n\t\treturn fmt.Errorf(\"invalid pid: %v\", string(p))\n\t}\n\n\tprocess, err := os.FindProcess(pid)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"process not found: %v\", err)\n\t}\n\n\tif err := process.Signal(syscall.Signal(0)); err != nil {\n\t\treturn fmt.Errorf(\"process signal(0) returned error: %w\", err)\n\t}\n\n\treturn nil\n}\n\nconst (\n\tpidFileName = \"daemon.pid\"\n\tlogFileName = \"daemon.log\"\n)","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/cmd/daemon/daemon.go#L107-L143","documentation":"`colima daemon status` reads the daemon pid file and parses its content with strconv.Atoi, deliberately discarding the parse error. Any content Atoi cannot parse in full (empty file, trailing newline, spaces, non-numeric text) yields pid 0 and this error fires, echoing the raw file bytes in the message. It means the pid file exists but is corrupt or malformed, not that the daemon misbehaved.","triggerScenarios":"Calling daemon status/start-stop plumbing when info.PidFile exists but is empty (daemon crashed mid-write), contains '123\\n' (strconv.Atoi rejects the trailing newline), has whitespace, or was written by a different colima version/profile with a different format.","commonSituations":"Unclean daemon shutdown (kill -9, host crash) truncating the pid file; running mixed colima versions (brew vs. nightly) sharing the daemon directory; manually editing or `echo $$ >`-ing the pid file; empty file left behind by a failed daemon start.","solutions":["Remove the stale pid file (the daemon is not running anyway): delete dir()/daemon.pid reported by daemon info, then run `colima daemon start`","If it recurs, stop the daemon cleanly with `colima daemon stop` instead of killing the process by hand","Patch daemon.go:123-126 to use strconv.Atoi(strings.TrimSpace(string(p))) and surface the parse error instead of ignoring it"],"exampleFix":"// before\npid, _ := strconv.Atoi(string(p))\nif pid == 0 {\n    return fmt.Errorf(\"invalid pid: %v\", string(p))\n}\n\n// after\npid, err := strconv.Atoi(strings.TrimSpace(string(p)))\nif err != nil || pid <= 0 {\n    return fmt.Errorf(\"invalid pid %q in %s: %w\", string(p), info.PidFile, err)\n}","handlingStrategy":"validation","validationCode":"// Go: verify the pid file parses BEFORE calling daemon status\nfunc pidFileValid(pidFile string) bool {\n    b, err := os.ReadFile(pidFile)\n    if err != nil {\n        return false\n    }\n    pid, err := strconv.Atoi(strings.TrimSpace(string(b)))\n    return err == nil && pid > 0\n}\n\nif !pidFileValid(daemon.Info().PidFile) {\n    _ = os.Remove(daemon.Info().PidFile) // stale; start fresh\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always stop the daemon with `colima daemon stop`; never kill it with kill -9, which can leave a truncated pid file","Do not hand-edit or truncate daemon.pid","If you maintain this code: use strconv.Atoi(strings.TrimSpace(string(p))) and propagate the parse error instead of discarding it"],"tags":["go","colima","daemon","pidfile","parsing"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}