juicedata/juicefs · error
failed to parse pid: %s
Error message
failed to parse pid: %s
What it means
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.
Source
Thrown at cmd/debug_windows.go:117
}
if arg == "mount" {
mountFound = true
continue
}
arg = strings.TrimRight(arg, "\\")
if strings.EqualFold(arg, mp) {
mpFound = true
}
}
if mpFound && mountFound {
// THE LAST PART IS PID
pid, err := strconv.Atoi(args[len(args)-1])
if err != nil {
return 0, fmt.Errorf("failed to parse pid: %s", args[len(args)-1])
}
return pid, nil
}
}
return 0, fmt.Errorf("cannot find the mount process for %s", mp)
}
func getProcessUserSid(pid int) (string, error) {
h, err := windows.OpenProcess(windows.PROCESS_QUERY_INFORMATION, false, uint32(pid))
if err != nil {
return "", err
}
defer windows.CloseHandle(h)
var token windows.Token
err = windows.OpenProcessToken(h, windows.TOKEN_QUERY, &token)
if err != nil {
View on GitHub (pinned to c9a67b23e8)
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
Example fix
// before
pid, err := strconv.Atoi(args[len(args)-1])
if err != nil {
return 0, fmt.Errorf("failed to parse pid: %s", args[len(args)-1])
}
// after
last := strings.TrimSpace(args[len(args)-1])
pid, err := strconv.Atoi(last)
if err != nil {
// fall back to scanning tokens from the end for a numeric pid
for i := len(args) - 1; i >= 0; i-- {
if p, e := strconv.Atoi(strings.TrimSpace(args[i])); e == nil {
pid, err = p, nil
break
}
}
if err != nil {
return 0, fmt.Errorf("failed to parse pid: %s", last)
}
} Defensive patterns
Strategy: try-catch
Validate before calling
// sanity-check the wmic row before trusting the last token as pid
// last token must be all digits
if n := len(args); n == 0 || !isAllDigits(strings.TrimSpace(args[n-1])) {
return fmt.Errorf("unexpected wmic row: %q", sline)
} Type guard
func isAllDigits(s string) bool {
if s == "" {
return false
}
for _, r := range s {
if r < '0' || r > '9' {
return false
}
}
return true
} Try / catch
foundPid, err := findMountProcess(mp)
if err != nil {
if strings.Contains(err.Error(), "failed to parse pid") {
// fall back to reading pid from the mountpoint config file
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to find command line for pid: %d
- cannot find command line for pid %d. If the juicefs are moun
- failed to exec command line: %s, %s
- failed to find mount process
- invalid unit
AI-assisted analysis of juicedata/juicefs@c9a67b23e8 (2026-09-06).
Data as JSON: /api/errors/724f1ef44989a3c9.
Report an issue: GitHub.