{"record":{"id":"9b6dbd6117dd527c","repo":"docker/cli","slug":"failed-to-parse-hook-template-flagvalue-no-flags","errorCode":null,"errorMessage":"failed to parse hook template: flagValue: no flags found","messagePattern":"failed to parse hook template: flagValue: no flags found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cli-plugins/hooks/template.go","lineNumber":79,"sourceCode":"\treturn c.command()\n}\n\n// command returns the name of the (sub)command for which the hook was invoked.\nfunc (c commandInfo) command() string {\n\tif c.cmd == nil {\n\t\treturn \"\"\n\t}\n\treturn c.cmd.Name()\n}\n\n// flagValue returns the value that was set for the given flag when the hook was invoked.\nfunc (c commandInfo) flagValue(flagName string) (string, error) {\n\tif c.cmd == nil {\n\t\treturn \"\", fmt.Errorf(\"%w: flagValue: cmd is nil\", ErrHookTemplateParse)\n\t}\n\tf := c.cmd.Flag(flagName)\n\tif f == nil {\n\t\treturn \"\", fmt.Errorf(\"%w: flagValue: no flags found\", ErrHookTemplateParse)\n\t}\n\treturn f.Value.String(), nil\n}\n\n// argValue returns the value of the nth argument.\nfunc (c commandInfo) argValue(n int) (string, error) {\n\tif c.cmd == nil {\n\t\treturn \"\", fmt.Errorf(\"%w: arg: cmd is nil\", ErrHookTemplateParse)\n\t}\n\tflags := c.cmd.Flags()\n\tv := flags.Arg(n)\n\tif v == \"\" && n >= flags.NArg() {\n\t\treturn \"\", fmt.Errorf(\"%w: arg: %dth argument not set\", ErrHookTemplateParse, n)\n\t}\n\treturn v, nil\n}\n","sourceCodeStart":61,"sourceCodeEnd":96,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli-plugins/hooks/template.go#L61-L96","documentation":"Returned (wrapped in ErrHookTemplateParse) by commandInfo.flagValue when cobra's Flag(name) returns nil, meaning the named flag does not exist on the command for which the hook was invoked. flagValue is the 'flagValue' template func used in hook message templates.","triggerScenarios":"A hook template referencing {{flagValue \"nonexistent\"}} for a flag that the current (sub)command does not define.","commonSituations":"A plugin template written for one command reused against a subcommand lacking that flag, or a typo in the flag name, or a flag renamed/removed in a newer CLI version.","solutions":["Reference only flags that exist on the command that triggers the hook.","Fix typos in the flag name inside the template.","Update the plugin template after a CLI version renames or removes a flag."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// verify the flag exists on the command before referencing it in a template\nif cmd.Flag(flagName) == nil {\n    return fmt.Errorf(\"flag %q not defined on %s\", flagName, cmd.Name())\n}","typeGuard":null,"tryCatchPattern":"if _, err := msgContext.flagValue(name); err != nil {\n    // skip or use a default\n}","preventionTips":["Reference only flags present on the triggering command.","Update templates when flags are renamed across CLI versions."],"tags":["hooks","cli-plugins","template","flags"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}