docker/cli ยท error

expected a pointer to a struct, got a pointer to %v

Error message

expected a pointer to a struct, got a pointer to %v

What it means

Error "expected a pointer to a struct, got a pointer to %v" thrown in docker/cli.

Source

Thrown at cli/command/formatter/reflect.go:35

	m, err := marshalMap(x)
	if err != nil {
		return nil, err
	}
	return json.Marshal(m)
}

// marshalMap marshals x to map[string]any
func marshalMap(x any) (map[string]any, error) {
	val := reflect.ValueOf(x)
	if val.Kind() != reflect.Pointer {
		return nil, fmt.Errorf("expected a pointer to a struct, got %v", val.Kind())
	}
	if val.IsNil() {
		return nil, errors.New("expected a pointer to a struct, got nil pointer")
	}
	valElem := val.Elem()
	if valElem.Kind() != reflect.Struct {
		return nil, fmt.Errorf("expected a pointer to a struct, got a pointer to %v", valElem.Kind())
	}
	typ := val.Type()
	m := make(map[string]any)
	for i := 0; i < val.NumMethod(); i++ {
		k, v, err := marshalForMethod(typ.Method(i), val.Method(i))
		if err != nil {
			return nil, err
		}
		if k != "" {
			m[k] = v
		}
	}
	return m, nil
}

var unmarshallableNames = map[string]struct{}{"FullHeader": {}}

// marshalForMethod returns the map key and the map value for marshalling the method.

View on GitHub (pinned to e9452d6e78)

When it happens

Trigger: Thrown at cli/command/formatter/reflect.go:35 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01). Data as JSON: /data/errors/f7a512782fecf04e.json. Report an issue: GitHub.