{"record":{"id":"dc68b18a2c520b7e","repo":"docker/cli","slug":"failed-to-parse-template-w","errorCode":null,"errorMessage":"failed to parse template: %w","messagePattern":"failed to parse template: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/list.go","lineNumber":87,"sourceCode":"}\n\nfunc buildContainerListOptions(options *psOptions) (client.ContainerListOptions, error) {\n\tlistOptions := client.ContainerListOptions{\n\t\tAll:     options.all,\n\t\tLimit:   options.last,\n\t\tSize:    options.size,\n\t\tFilters: options.filter.Value(),\n\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,","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/list.go#L69-L105","documentation":"Returned by list.go:87 when templates.Parse fails on the value of `docker ps --format`. The format string is parsed as a Go text/template every time --format is provided so that errors surface consistently. The wrapped %w is the template parse error.","triggerScenarios":"`docker ps --format` with a malformed Go template: unbalanced `{{ }}`, unknown function, bad pipeline, or a syntax error.","commonSituations":"Typo in a format template, copy-paste of a format meant for another command, or a template using a function not registered in the Docker template engine.","solutions":["Validate the template syntax: balance {{ }} and use supported functions.","Use the built-in table/json/raw formats instead of a custom template if unsure.","Test incrementally starting from a known-good template like {{.ID}} {{.Names}}."],"exampleFix":"# before\ndocker ps --format \"{{.ID {{.Names}}\"\n\n# after\ndocker ps --format \"{{.ID}} {{.Names}}\"","handlingStrategy":"validation","validationCode":"import \"text/template\"\nif _, err := template.New(\"f\").Funcs(dockerFuncs).Parse(formatStr); err != nil {\n    return fmt.Errorf(\"invalid --format template: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"// Parse failures are deterministic; fix the template rather than retry.\nif err != nil && strings.Contains(err.Error(), \"failed to parse template\") {\n    /* fall back to default formatting */\n}","preventionTips":["Test custom --format strings before scripting them.","Prefer built-in table/json formats when possible.","Balance every {{ with a }}."],"tags":["container","list","template","cli","flag-validation"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}