{"record":{"id":"724f1ef44989a3c9","repo":"juicedata/juicefs","slug":"failed-to-parse-pid-s","errorCode":null,"errorMessage":"failed to parse pid: %s","messagePattern":"failed to parse pid: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/debug_windows.go","lineNumber":117,"sourceCode":"\t\t\t}\r\n\r\n\t\t\tif arg == \"mount\" {\r\n\t\t\t\tmountFound = true\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\r\n\t\t\targ = strings.TrimRight(arg, \"\\\\\")\r\n\r\n\t\t\tif strings.EqualFold(arg, mp) {\r\n\t\t\t\tmpFound = true\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif mpFound && mountFound {\r\n\t\t\t// THE LAST PART IS PID\r\n\t\t\tpid, err := strconv.Atoi(args[len(args)-1])\r\n\t\t\tif err != nil {\r\n\t\t\t\treturn 0, fmt.Errorf(\"failed to parse pid: %s\", args[len(args)-1])\r\n\t\t\t}\r\n\t\t\treturn pid, nil\r\n\t\t}\r\n\t}\r\n\r\n\treturn 0, fmt.Errorf(\"cannot find the mount process for %s\", mp)\r\n}\r\n\r\nfunc getProcessUserSid(pid int) (string, error) {\r\n\th, err := windows.OpenProcess(windows.PROCESS_QUERY_INFORMATION, false, uint32(pid))\r\n\tif err != nil {\r\n\t\treturn \"\", err\r\n\t}\r\n\tdefer windows.CloseHandle(h)\r\n\r\n\tvar token windows.Token\r\n\terr = windows.OpenProcessToken(h, windows.TOKEN_QUERY, &token)\r\n\tif err != nil {\r","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/cmd/debug_windows.go#L99-L135","documentation":"When a wmic output line matches both the mountpoint and the 'mount' subcommand, findMountProcess assumes the last whitespace-separated token of the wmic line is the ProcessId and parses it with strconv.Atoi. If that token is not a number (wmic column ordering changed, trailing whitespace/CR artifacts, or the CommandLine itself ends with a non-numeric token), parsing fails and this error is raised.","triggerScenarios":"A wmic output line for a juicefs mount process was matched by mountpoint+subcommand, but `strconv.Atoi(args[len(args)-1])` failed — e.g. wmic returned columns in an order where the pid is not last, output contains trailing carriage returns/embedded spaces, or the mount command line's last argument is not the pid appended by wmic.","commonSituations":"Non-English/modified wmic formatting or different Windows builds altering column order; mount command lines containing quoted arguments with spaces that shift token positions; Windows line-ending artifacts (\\r) left on the last token; running debug while the mount command line was constructed unusually (extra flags after the mountpoint).","solutions":["Inspect the raw wmic output (`wmic process where name='juicefs.exe' get CommandLine,ProcessId`) and check what the last token actually is","Upgrade JuiceFS to a version that parses ProcessId as a separate wmic column instead of assuming it is the last token","Avoid mount command lines with unquoted spaces in the mountpoint/flags, or quote paths containing spaces when mounting","Run debug as admin to get clean, complete wmic rows; a truncated row can misplace the pid"],"exampleFix":"// before\npid, err := strconv.Atoi(args[len(args)-1])\nif err != nil {\n\treturn 0, fmt.Errorf(\"failed to parse pid: %s\", args[len(args)-1])\n}\n// after\nlast := strings.TrimSpace(args[len(args)-1])\npid, err := strconv.Atoi(last)\nif err != nil {\n\t// fall back to scanning tokens from the end for a numeric pid\n\tfor i := len(args) - 1; i >= 0; i-- {\n\t\tif p, e := strconv.Atoi(strings.TrimSpace(args[i])); e == nil {\n\t\t\tpid, err = p, nil\n\t\t\tbreak\n\t\t}\n\t}\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to parse pid: %s\", last)\n\t}\n}","handlingStrategy":"try-catch","validationCode":"// sanity-check the wmic row before trusting the last token as pid\n// last token must be all digits\nif n := len(args); n == 0 || !isAllDigits(strings.TrimSpace(args[n-1])) {\n\treturn fmt.Errorf(\"unexpected wmic row: %q\", sline)\n}","typeGuard":"func isAllDigits(s string) bool {\n\tif s == \"\" {\n\t\treturn false\n\t}\n\tfor _, r := range s {\n\t\tif r < '0' || r > '9' {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}","tryCatchPattern":"foundPid, err := findMountProcess(mp)\nif err != nil {\n\tif strings.Contains(err.Error(), \"failed to parse pid\") {\n\t\t// fall back to reading pid from the mountpoint config file\n\t}\n\treturn err\n}","preventionTips":["Quote any mountpoint/paths containing spaces so command-line tokens stay well-formed","Prefer resolving the pid from the mountpoint config (cfg.Pid) over wmic parsing","Trim \\r and whitespace from wmic tokens before numeric parsing","Test debug against wmic output on your exact Windows build; column order can vary across versions"],"tags":["windows","wmic","parsing","strconv"],"backgroundTag":"invalid-argument-format","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}