{"record":{"id":"b1e023123860617a","repo":"docker/cli","slug":"template-parsing-error-w-b1e023","errorCode":null,"errorMessage":"template parsing error: %w","messagePattern":"template parsing error: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/inspect/inspector.go","lineNumber":62,"sourceCode":"}\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\ntype GetRefFunc func(ref string) (any, []byte, error)\n\n// Inspect fetches objects by reference using GetRefFunc and writes the json\n// representation to the output writer.\nfunc Inspect(out io.Writer, references []string, tmplStr string, getRef GetRefFunc) error {\n\tif out == nil {\n\t\treturn errors.New(\"no output stream\")\n\t}\n\tinspector, err := NewTemplateInspectorFromString(out, tmplStr)\n\tif err != nil {\n\t\treturn cli.StatusError{StatusCode: 64, Status: err.Error()}\n\t}","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/inspect/inspector.go#L44-L80","documentation":"Returned by `NewTemplateInspectorFromString` (inspector.go:60-63) when `templates.Parse(tmplStr)` fails on the `--format` value passed to any `docker inspect`-style command. The format string is compiled as a Go text/template, so any syntax error (unclosed `{{`, bad pipeline, undefined function) produces this. The %w wraps the underlying text/template parse error.","triggerScenarios":"Running `docker inspect --format '{{.Id' img` (unclosed action), `--format '{{foo .}}'` (undefined function), or any malformed Go template action. Also triggered by stray characters or unescaped braces.","commonSituations":"Hand-writing a custom format string, copy-paste introducing smart quotes, referencing a helper function that isn't registered in the templates package.","solutions":["Balance every `{{` with `}}` and validate the template locally: `go run` a snippet using text/template.","Use only documented template functions (json, join, lower, etc.) from the docker CLI templates package.","Fall back to the built-in formats: `--format json` or omit --format for default indented output.","Quote the format string in single quotes to prevent shell interpolation of braces."],"exampleFix":"# before\ndocker inspect --format '{{.Config.Cmd' img\n# after\ndocker inspect --format '{{.Config.Cmd}}' img","handlingStrategy":"validation","validationCode":"// pre-validate a Go format template before passing to --format\nimport \"text/template\"\nif _, err := template.New(\"f\").Parse(formatStr); err != nil {\n    return fmt.Errorf(\"invalid --format template: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := cli.RunInspect(formatStr); err != nil {\n    if strings.Contains(err.Error(), \"template parsing error\") {\n        return fmt.Errorf(\"fix your --format template syntax: %w\", err)\n    }\n    return err\n}","preventionTips":["Test format strings with a tiny Go text/template program first.","Prefer the built-in --format json when unsure.","Single-quote the format string in the shell."],"tags":["inspect","template","format","docker-cli"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}