{"id":"6c8934367f8f7d0a","repo":"docker/cli","slug":"no-output-stream","errorCode":null,"errorMessage":"no output stream","messagePattern":"no output stream","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/inspect/inspector.go","lineNumber":50,"sourceCode":"}\n\n// NewTemplateInspector creates a new inspector with a template.\nfunc NewTemplateInspector(out io.Writer, tmpl *template.Template) *TemplateInspector {\n\tif out == nil {\n\t\tout = io.Discard\n\t}\n\treturn &TemplateInspector{\n\t\tout:    out,\n\t\tbuffer: new(bytes.Buffer),\n\t\ttmpl:   tmpl,\n\t}\n}\n\n// NewTemplateInspectorFromString creates a new TemplateInspector from a string\n// which is compiled into a template.\nfunc NewTemplateInspectorFromString(out io.Writer, tmplStr string) (Inspector, error) {\n\tif out == nil {\n\t\treturn nil, errors.New(\"no output stream\")\n\t}\n\tif tmplStr == \"\" {\n\t\treturn NewIndentedInspector(out), nil\n\t}\n\n\tif tmplStr == \"json\" {\n\t\treturn NewJSONInspector(out), nil\n\t}\n\n\ttmpl, err := templates.Parse(tmplStr)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"template parsing error: %w\", err)\n\t}\n\treturn NewTemplateInspector(out, tmpl), nil\n}\n\n// GetRefFunc is a function which used by Inspect to fetch an object from a\n// reference","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/inspect/inspector.go#L32-L68","documentation":"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.)","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a real writer: the CLI's dockerCli.Out(), os.Stdout, or a *bytes.Buffer in tests","If you genuinely want to discard output, pass io.Discard explicitly rather than nil","Audit the call site's Cli construction to ensure its output stream is initialized before commands run"],"exampleFix":"// before\ninspector, err := inspect.NewTemplateInspectorFromString(nil, format)\n// after\ninspector, err := inspect.NewTemplateInspectorFromString(dockerCli.Out(), format)","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","inspect","nil-writer","go","library-usage"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}