JanDeDobbeleer/oh-my-posh · error
invalid docker ps output on line %d: expected 7 fields, got
Error message
invalid docker ps output on line %d: expected 7 fields, got %d
What it means
The docker segment runs "docker ps --format ..." with tab-separated output and expects exactly 7 fields per line. If any non-empty line splits into a different number of tab-separated fields, the output can't be mapped onto the Container struct and this error aborts the segment.
Source
Thrown at src/segments/docker.go:203
output, err := d.env.RunCommand(d.command.executable, d.command.args...)
if err != nil {
return nil, err
}
lines := strings.Split(strings.TrimSpace(output), "\n")
if len(lines) == 0 || (len(lines) == 1 && lines[0] == "") {
return nil, nil
}
containers := make([]Container, 0, len(lines))
for i, line := range lines {
line = strings.TrimRight(line, "\r")
fields := strings.Split(line, "\t")
if len(fields) != 7 {
return nil, fmt.Errorf("invalid docker ps output on line %d: expected 7 fields, got %d", i+1, len(fields))
}
containers = append(containers, Container{
ID: fields[0],
Image: fields[1],
Command: fields[2],
Created: fields[3],
Status: fields[4],
Ports: fields[5],
Names: fields[6],
})
}
return containers, nil
}
View on GitHub (pinned to 0976794618)
Solutions
- Check `docker ps --format '<the format the segment uses>'` manually - verify each line has exactly 7 tab-separated columns.
- Update (or check the version of) the docker CLI - mismatched --format support is the usual culprit.
- Ensure no shell alias/wrapper redefines docker ps with different output for the user running oh-my-posh.
- Look at the actual first failing line number in the error to see the offending output and adapt the format.
Defensive patterns
Strategy: validation
Validate before calling
// Pre-check docker output shape before consuming it
out, err := exec.Command("docker", "ps", "--format", formatStr).Output()
if err == nil {
for i, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
if line != "" && len(strings.Split(strings.TrimRight(line, "\r"), "\t")) != 7 {
log.Printf("docker output shape mismatch at line %d", i+1)
}
}
} Try / catch
containers, err := dockerSegment.FetchContainers()
if err != nil && strings.Contains(err.Error(), "invalid docker ps output") {
// hide docker segment instead of failing the prompt
return nil
} Prevention
- Keep the docker CLI version compatible with the --format the segment uses
- Run `docker ps` manually with the segment's format to verify 7 tab-separated fields
- Remove shell aliases/wrappers that alter docker ps output for the shell user
- Update docker Desktop/CLI when upgrading oh-my-posh
When it happens
Trigger: The docker CLI output doesn't match the expected tab-separated 7-column format - typically because the installed docker version doesn't support the --format used, docker prints a warning/error line to stdout, or a container name/image contains characters altering the split.
Common situations: Very old or very new docker/podman versions changing default output; docker daemon warnings interleaved with data; localization or a wrapper script (alias) modifying output; line ending issues (the code trims \r but extra whitespace can remain).
Related errors
- gitstatus: truncated delta insert
- gitstatus: delta target size mismatch
- unclosed section:
- key-value delimiter not found:
- unable to find battery state based on output
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/a655589a9159ed57.
Report an issue: GitHub.