docker/cli · error
got wrong object to inspect
Error message
got wrong object to inspect
What it means
Internal type-assertion failure in the service pretty-print path: inspectFormatWrite expects each object returned by the getRef callback to be a swarm.Service, and errors if the assertion `serviceI.(swarm.Service)` fails. It indicates the inspect plumbing handed a non-Service value (or a pointer instead of a value) to the service formatter — a programming/integration bug rather than a user mistake.
Source
Thrown at cli/command/service/formatter.go:235
}
return networkNames
}
// inspectFormatWrite renders the context for a list of services
func inspectFormatWrite(fmtCtx formatter.Context, refs []string, getRef, getNetwork inspect.GetRefFunc) error {
if fmtCtx.Format != serviceInspectPrettyTemplate {
return inspect.Inspect(fmtCtx.Output, refs, string(fmtCtx.Format), getRef)
}
return fmtCtx.Write(&serviceInspectContext{}, func(format func(subContext formatter.SubContext) error) error {
for _, ref := range refs {
serviceI, _, err := getRef(ref)
if err != nil {
return err
}
service, ok := serviceI.(swarm.Service)
if !ok {
return errors.New("got wrong object to inspect")
}
if err := format(&serviceInspectContext{
Service: service,
networkNames: resolveNetworks(service, getNetwork),
}); err != nil {
return err
}
}
return nil
})
}
type serviceInspectContext struct {
swarm.Service
formatter.SubContext
// networkNames is a map from network IDs (as found in
// Networks[x].Target) to network names.View on GitHub (pinned to e9452d6e78)
Solutions
- If embedding the cli packages, ensure the getRef callback returns swarm.Service by value, not *swarm.Service or another type.
- Align docker/cli and moby/moby client library versions so inspect result types match.
- If hit from the stock docker binary, report it as a bug with `docker version` output — end users should never see this.
Example fix
// before (custom getRef) return &res.Service, res.Raw, err // after return res.Service, res.Raw, err // value, matches serviceI.(swarm.Service)
When it happens
Trigger: Only reachable when the pretty template is active and getRef returns something other than a swarm.Service value — e.g. custom code embedding the docker/cli packages passes *swarm.Service or another type, or an API-version mismatch causes decoding into a different type.
Common situations: Developers vendoring github.com/docker/cli and wiring their own GetRefFunc into inspectFormatWrite, or version skew between cli and moby client libraries where the inspect result type changed (value vs pointer).
Related errors
- --format is incompatible with human friendly format
- cannot supply extra formatting options to the pretty templat
- tty service logs only supported with --raw
- placement preference must be of the format "<strategy>=<arg>
- invalid credential spec: value must be prefixed with "config
AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01).
Data as JSON: /data/errors/e303bb5f075a098c.json.
Report an issue: GitHub.