{"record":{"id":"d4524fd8a98dc334","repo":"docker/cli","slug":"failed-to-execute-template-w","errorCode":null,"errorMessage":"failed to execute template: %w","messagePattern":"failed to execute template: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/list.go","lineNumber":95,"sourceCode":"\t}\n\n\tif options.nLatest && options.last == -1 {\n\t\tlistOptions.Limit = 1\n\t}\n\n\t// always validate template when `--format` is used, for consistency\n\tif len(options.format) > 0 {\n\t\ttmpl, err := templates.Parse(options.format)\n\t\tif err != nil {\n\t\t\treturn client.ContainerListOptions{}, fmt.Errorf(\"failed to parse template: %w\", err)\n\t\t}\n\n\t\toptionsProcessor := formatter.NewContainerContext()\n\n\t\t// This shouldn't error out but swallowing the error makes it harder\n\t\t// to track down if preProcessor issues come up.\n\t\tif err := tmpl.Execute(io.Discard, optionsProcessor); err != nil {\n\t\t\treturn client.ContainerListOptions{}, fmt.Errorf(\"failed to execute template: %w\", err)\n\t\t}\n\n\t\t// if `size` was not explicitly set to false (with `--size=false`)\n\t\t// and `--quiet` is not set, request size if the template requires it\n\t\tif !options.quiet && !listOptions.Size && !options.sizeChanged {\n\t\t\t// The --size option isn't set, but .Size may be used in the template.\n\t\t\t// Parse and execute the given template to detect if the .Size field is\n\t\t\t// used. If it is, then automatically enable the --size option. See #24696\n\t\t\t//\n\t\t\t// Only requesting container size information when needed is an optimization,\n\t\t\t// because calculating the size is a costly operation.\n\n\t\t\tif _, ok := optionsProcessor.FieldsUsed[\"Size\"]; ok {\n\t\t\t\tlistOptions.Size = true\n\t\t\t}\n\t\t}\n\t}\n","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/list.go#L77-L113","documentation":"Returned by list.go:95 when a parsed --format template executes against a dry-run optionsProcessor (io.Discard) and fails. Parsing succeeded but execution revealed a problem, e.g. referencing a field that errors during the dry-run pass.","triggerScenarios":"A `docker ps --format` template that parses fine but errors at execution time during the pre-flight dry run, such as calling a template function in a way that panics/errors when invoked on the container context object.","commonSituations":"A template field or function that is valid syntactically but invalid semantically for the container formatter context, or a custom function with wrong arguments.","solutions":["Simplify the template to isolate the failing field/function.","Confirm each field is valid for the container context (use docker ps --format '{{json .}}' to inspect).","Avoid calling functions with argument shapes the template engine rejects."],"exampleFix":"# inspect available fields\ndocker ps --format '{{json .}}'\n\n# then build the template using only valid fields\n\n# before\ndocker ps --format '{{.NonExistentField}}'\n# after\ndocker ps --format '{{.Names}}'","handlingStrategy":"validation","validationCode":"// Parse then execute against a throwaway context to catch execution errors:\ntmpl, err := templates.Parse(format)\nif err != nil { return err }\nif err := tmpl.Execute(io.Discard, formatter.NewContainerContext()); err != nil {\n    return fmt.Errorf(\"template executes but fails: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"// Execution errors are usually semantic; simplify the template.\nif err != nil && strings.Contains(err.Error(), \"failed to execute template\") {\n    /* fall back to a minimal valid template */\n}","preventionTips":["Inspect available fields with `docker ps --format '{{json .}}'`.\nAvoid referencing fields/functions that do not exist in the container context.\nBuild templates incrementally."],"tags":["container","list","template","cli"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}