docker/cli · error

no output stream

Error message

no output stream

What it means

NewTemplateInspectorFromString (cli/command/inspect/inspector.go:48-51) builds the inspector that renders `docker inspect --format` output. It requires a non-nil io.Writer; if out is nil there is nowhere to render the template/JSON, so it fails fast with 'no output stream' instead of deferring a nil-pointer panic to write time. (Note NewTemplateInspector itself substitutes io.Discard for nil, but the string-based constructor deliberately rejects nil.)

Source

Thrown at cli/command/inspect/inspector.go:50

}

// NewTemplateInspector creates a new inspector with a template.
func NewTemplateInspector(out io.Writer, tmpl *template.Template) *TemplateInspector {
	if out == nil {
		out = io.Discard
	}
	return &TemplateInspector{
		out:    out,
		buffer: new(bytes.Buffer),
		tmpl:   tmpl,
	}
}

// NewTemplateInspectorFromString creates a new TemplateInspector from a string
// which is compiled into a template.
func NewTemplateInspectorFromString(out io.Writer, tmplStr string) (Inspector, error) {
	if out == nil {
		return nil, errors.New("no output stream")
	}
	if tmplStr == "" {
		return NewIndentedInspector(out), nil
	}

	if tmplStr == "json" {
		return NewJSONInspector(out), nil
	}

	tmpl, err := templates.Parse(tmplStr)
	if err != nil {
		return nil, fmt.Errorf("template parsing error: %w", err)
	}
	return NewTemplateInspector(out, tmpl), nil
}

// GetRefFunc is a function which used by Inspect to fetch an object from a
// reference

View on GitHub (pinned to e9452d6e78)

Solutions

  1. Pass a real writer: the CLI's dockerCli.Out(), os.Stdout, or a *bytes.Buffer in tests
  2. If you genuinely want to discard output, pass io.Discard explicitly rather than nil
  3. Audit the call site's Cli construction to ensure its output stream is initialized before commands run

Example fix

// before
inspector, err := inspect.NewTemplateInspectorFromString(nil, format)
// after
inspector, err := inspect.NewTemplateInspectorFromString(dockerCli.Out(), format)

When it happens

Trigger: Calling inspect.NewTemplateInspectorFromString(nil, tmplStr) — typically from custom Go code embedding the docker/cli inspect package, or from a command wired up with a Cli whose Out() returns nil.

Common situations: Programs vendoring github.com/docker/cli and building inspect-style commands without wiring an output stream; unit tests constructing a command.Cli mock with a nil output; refactors that pass a struct's uninitialized writer field.

Related errors


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